Home > Articles > Programming > C#

  • Print
  • + Share This
Like this article? We recommend

The default Keyword

Another very useful item in C# is the overloaded use of the default keyword. This scheme allows you to determine the default value for a given type, as in Listing 15.

Listing 15 The default keyword in action.

Console.WriteLine("Default values {0} {1} ", default(bool), default(int));

The code in Listing 15 produces the following output:

Default values False 0

The default keyword returns a value of null for a reference type and a suitable default value for a value type. So, in Listing 15, the default value for a Boolean type is False, while for an int the default value is 0.

  • + Share This
  • 🔖 Save To Your Account