I have been trying to understand the difference between ref
and out
in C# and faced this misunderstanding of a++
and ++a
.
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
}
}
can anyone explain why a++
didn't increment to 5 in the above code.