CSharp - Operator Default Operator

Introduction

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.

Demo

using System;

class Program//w  w w  .  j  a v  a 2s.co  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));
        //null
        bool b2 = (default(string) == null);//True
        Console.WriteLine("default(string) is  null ? Answer:{0}", b2);
    }
}

Result

Related Topics