Method Parameters Actual Reference in C#



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: 20
After member assignment: 50
After new object creation: 20
After method call: 20

0 Comment's

Comment Form

Submit Comment