C# Null

Description

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.

Example

The following code assigns null to myHouse (myHouse will no longer reference an object).


class House/* w  w  w . j a va 2s .c o m*/
{

}

class MainClass
{
  public static void Main()
  {
    House myHouse;
    myHouse = new House();
    myHouse = null;
  }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Custom Types »




C# Class
C# Struct
C# Interface
C# Inheritance
C# Namespace
C# Object
C# Delegate
C# Lambda
C# Event
C# Enum
C# Attribute
C# Generics
C# Preprocessor