C# Null

In this chapter you will learn:

  1. What is C# Null Value
  2. Example for C# Null Value

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 v  a2s .c om
{

}

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

The code above generates the following result.

Next chapter...

What you will learn in the next chapter:

  1. What are C# Nullable Types
  2. Nullable Struct
  3. Example for C# Nullable Types
Home »
  C# Tutorial »
    C# Types »
      C# Object
C# Object
C# new operator
C# this Reference
C# Null
C# Nullable Types
C# ToString Method
C# Object Initializers
C# GetHashCode
C# Object Casting and Reference Conversions