Default operator in C#

CsharpProgrammingServer Side Programming

Using the default, you can get the default value of every reference and value type. The expressions set as default are evaluated at compile-time.

To get the default for int −

default(int);

To get the default for long −

default(long)

Let us see the code to display default values −

Example

 Live Demo

using System;

public class Demo {
   public static void Main() {
      int val1 = default(int);
      long val2 = default(long);
      bool val3 = default(bool);

      // default for int
      Console.WriteLine(val1);

      // default for long
      Console.WriteLine(val2);

      // default for bol
      Console.WriteLine(val3);
   }
}

Output

0
0
False
raja
Published on 04-Sep-2018 10:43:13
Advertisements