Please look at the following code-
public class Program
{
public static void Main()
{
A ob = new A();
ob.x = 120;
ob.Name = "No";
GO(ob);
Console.WriteLine(ob.x);
}
public static void GO(A obj)
{
obj.x = 50;
obj.Name = "Local";
obj = null;
}
}
in console It prints the value of x 50. but when I am using ref keyword it is giving null reference exception. My question is if object is reference type it should give null reference exception even if I don't use ref. and if it is not then value of x in console should be 120. I am unable to understand this behavior. Please explain whats happening here when we use ref and when we don't.