Demonstrate the default keyword : Generic Class : Generics C# Source Code


Custom Search

C# Source Code » Generics » Generic Class »

 

Demonstrate the default keyword









    


using System;

class MyClass {
}

class Test<T> {
  public T obj;

  public Test() {
    obj = default(T);
  }
}

class DefaultDemo {
  public static void Main() {
    Test<MyClass> x = new Test<MyClass>();

    if(x.obj == null)
      Console.WriteLine("x.obj is null.");

    Test<int> y = new Test<int>();

    if(y.obj == 0)
      Console.WriteLine("y.obj is 0.");
  }
}
           
       
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo Generics
» Generic Class