I want to make the object null using a static method. For explanation, I have created a sample code -
class Program
{
static void Main(string[] args)
{
Car car = new Car();
car.Name = "Audi";
makeNull(car);
Console.WriteLine(car.Name);
Console.ReadKey();
}
static void makeNull(Car c)
{
c = null;
}
}
class Car
{
public string Name;
}
//Output - Audi
I was expecting a Null Exception for the above code but surprisingly got "Audi" as output. Can anyone explain why exactly it is behaving like this ?