I've found a really cool feature of a compilator. However, I cannot understand logic of this behaviour.
static int IncrementValue(ref int i) { return i++;}
and Main method:
static void Main(string[] args)
{
int a = 2;
int b = IncrementValue(ref a);
Console.WriteLine(a+b);
}
The output is 5.
My question is:
- Why is "b" field equal 2? (In my view, it ought to be 3 as "ref" keyword is not copying by value, but the keyword takes field by value. Consequently, "b" should be as "a+1")