null reference
In this chapter you will learn:
Use null reference
null is a constant value to tell that the reference value is not pointing to anywhere or no value has been set for the reference value.
The following code assigns null to myHouse (myHouse will no longer reference an object).
class House//from j a v a 2s . c o m
{
public string make;
public string model;
public string color;
public int yearBuilt;
public void Start()
{
System.Console.WriteLine(model + " started");
}
public void Stop()
{
System.Console.WriteLine(model + " stopped");
}
}
class MainClass
{
public static void Main()
{
House myHouse;
myHouse = new House();
myHouse = null;
}
}
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » Class