CSharp - Operator Default Operator


In the context of generics, default initializes generic types with their default values.

The default value for a reference type is null and the default value of a value type is bitwise zero.


using System;

class Program//from  w ww  .  j a v  a2 s  .c o m
    static void Main(string[] args)
        Console.WriteLine("default(int) is {0}", default(int));//0
        bool b1 = (default(int) == null);//False
        Console.WriteLine("default(int) is null ?Answer: {0}", b1);
        Console.WriteLine("default(string) is {0}", default(string));
        bool b2 = (default(string) == null);//True
        Console.WriteLine("default(string) is  null ? Answer:{0}", b2);


Related Topics