Method Parameters Actual Reference in C#
using System.IO; using System; class MyClass { public int Value = 20; } class MethodParametersActualReference { static void RefAsParameter(ref MyClass objByRef) { objByRef.Value = 50; Console.WriteLine("After member assignment: {0}", objByRef.Value); objByRef = new MyClass(); Console.WriteLine("After new object creation: {0}", objByRef.Value); } static void Main() { MyClass obj = new MyClass(); Console.WriteLine("Before method call: {0}", obj.Value); RefAsParameter(ref obj); Console.WriteLine("After method call: {0}", obj.Value); } }
Before method call: 20After member assignment: 50After new object creation: 20After method call: 20