C# 试图编写一个程序来理解satnd pre&;post增量和一元运算符 使用系统; 命名空间一元运算符 { 类一元运算符 { //启动前和启动后检查及示例 公共INTA=0; 公共整数预增量() //此处显示错误(并非所有代码路径都返回值) { //我想在这里创建两个方法 //一个用于增量前,另一个用于增量后 //但当我输入程序时,我遇到了上面的错误 //我没有完成代码 //我想知道增量前和增量后是如何工作的 对于(a=0;a

C# 试图编写一个程序来理解satnd pre&;post增量和一元运算符 使用系统; 命名空间一元运算符 { 类一元运算符 { //启动前和启动后检查及示例 公共INTA=0; 公共整数预增量() //此处显示错误(并非所有代码路径都返回值) { //我想在这里创建两个方法 //一个用于增量前,另一个用于增量后 //但当我输入程序时,我遇到了上面的错误 //我没有完成代码 //我想知道增量前和增量后是如何工作的 对于(a=0;a,c#,C#,这个小程序展示了前增量和后增量是如何工作的 using System; namespace UnaryOperators { class UnaryOperators { //pre and post incerment checking and examples public int a=0; public int PreIncrement() //shows error here(not all code pa

这个小程序展示了前增量和后增量是如何工作的

using System;
namespace UnaryOperators
{
    class UnaryOperators
    {
        //pre and post incerment checking and examples
        public int a=0;

        public int PreIncrement()
        //shows error here(not all code paths return value)
        {
            //what i am trying to do here is i want to create 2 methods 
            //one for pre increment and other for post increment
            //but when i am typing program i stuck with above error so 
            //i didn't complete the code 
            //i want to know how pre increment and post incerment work 
            for(a = 0; a < 10; a++)
            {
                Console.WriteLine("PreIncrement value of a is "+a);
                return a;
            }
        }
        public static void Main(string[]args)
        {
            /*
            //if any one gives me a program as an example i will be really thankful
            //please give me an example to understand pre and post increments 
            // if you can understand anything of my code help me solve it
            // (but honestly think my code is shit)
            */
        }
    }
}
类程序
{
静态void Main(字符串[]参数)
{
WriteLine(“pre{0}之后,PreInc());
Console.WriteLine();
WriteLine(“在post{0}之后”,PostInc());
Console.ReadLine();
}
公共静态int PreInc()
{
int a=0;
做{
WriteLine(“a的预增量值为{0}”,++a);
}a<10;
返回a;
}
公共静态int PostInc()
{
int a=0;
做{
WriteLine(“a的后增量值为{0}”,a++);
}a<10;
返回a;
}
}

不要将你的问题写成代码注释;把它放在代码之外。至于您的问题,只需阅读错误消息;它很好地描述了问题所在。
class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("After pre {0}", PreInc());
        Console.WriteLine();
        Console.WriteLine("After post {0}", PostInc());
        Console.ReadLine();
    }

    public static int PreInc()
    {
        int a = 0;

        do {
            Console.WriteLine("PreIncrement value of a is {0}", ++a);
        } while (a < 10);

        return a;
    }

    public static int PostInc()
    {
        int a = 0;

        do {
            Console.WriteLine("PostIncrement value of a is {0}", a++);
        } while (a < 10);

        return a;
    }
}