I have the following code:
static void Main(string[] args)
{
myclass c = new myclass();
c.test1 = 1;
myclass c2 = TestPassByValByRef(c);
Console.WriteLine("c.Test1: {0}", c.test1);
Console.WriteLine("c2.Test1: {0}", c2.test1);
Console.ReadLine();
}
private static myclass TestPassByValByRef(myclass c)
{
Console.WriteLine("Before NowPassByRef c.Test1: {0}", c.test1);
NowPassByRef(ref c);
Console.WriteLine("After NowPassByRef c.Test1: {0}", c.test1);
return c;
}
private static void NowPassByRef(ref myclass c)
{
c = new myclass();
c.test1 = 10;
c.test2 = 25;
}
The output is that c2 retains the changed value, whereas c does not.
My question is this: What happens to c
in TestPassByValByRef
?