I have made some ref keyword tests and there is one think I can\'t understand:
static void Test(ref int a, ref int b)
{
Console.WriteLine(In
I know, that int is a value type but here it should pass references to the same object.
Yes, the reference passed to the method are the same, but they are boxed (converted to object/reference type) in the ReferenceEquals method.
That is why the result of your test returns false, since you are comparing references of two different objects, due to boxing.
See: Object.ReferenceEquals Method
When comparing value types. If
objAandobjBare value types, they are boxed before they are passed to theReferenceEqualsmethod. This means that if bothobjAandobjBrepresent the same instance of a value type, theReferenceEqualsmethod nevertheless returns false