static void Main6() { Class3 o = new Class3(); o.i = 100; //DoSomething1(o); //DoSomething2(o); DoSomething3(ref o); Console.WriteLine(o.i); Console.ReadLine(); }
static void Main() { Class3 o1 = new Class3(); Class3 o2 = new Class3(); o1.i = 100; o2.i = 200; o1 = o2; o2.i = 300; Console.WriteLine(o1.i); Console.WriteLine(o2.i); //300,300 Console.ReadLine(); }
//reference type passed as ref - if new object is created, the calling code(Main) points to the new object static void DoSomething3(ref Class3 obj) //obj = o { obj = new Class3(); obj.i = 200; }
//reference type - changes made in func reflect back in calling code static void DoSomething1(Class3 obj) { obj.i = 200; }