我一直在试图理解C#ref
和out
之间的差异,面临的a++
和++a
这种误解。A ++没有在C#程序增加
class Program
{
static void Main (string [] args)
{
int a = 3;
incr ( a) ;
Console.ReadKey();
}
public static void incr ( int a) // a = 3
{
Console.WriteLine (++a); // a incremented to 4
Console.WriteLine (a++); // a should be incremented to 5 , but it is still 4
}
}
任何人都可以解释为什么a++
没有增加到5在上述代码。
可你检查你的代码,我想你指的是第一个'+了'应该是一个''+向右? –
检查出[这里](http://stackoverflow.com/questions/3346450/what-is-the-difference-between-i-andi-i)@HassanNahhal –
@ M.kazemAkhgary非常感谢,我检查了所有问题,有一个人说,答案错误,声誉很高,我读了他的答案,但很难理解。 –