In C# what is the difference between myInt++ and ++myInt?

后端 未结 11 1819
我寻月下人不归
我寻月下人不归 2020-12-06 03:11

I\'m having a hard time understanding what the difference is between incrementing a variable in C# this way:

myInt++;

and

         


        
11条回答
  •  抹茶落季
    2020-12-06 03:32

    It determines when the result for that operation is returned.

    Here's an example from the MSDN site:

    static void Main() 
    {
        double x;
        x = 1.5;
        Console.WriteLine(++x);
        x = 1.5;
        Console.WriteLine(x++);
        Console.WriteLine(x);
    }
    

    And the ouput:

    2.5
    1.5
    2.5
    

提交回复
热议问题