Method Parameters Actual Reference C# with Example



Method Parameters Actual Reference C# with Example

 using System;

namespace CSharpFundamentals
{
	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 );
		}
    }
}
 

0 Comment's

Comment Form

Submit Comment