.Net C# the default keyword

Default returns the default value when the applied type has not been initialized.

using System;

namespace CsharpDefaultDemo
{
    class CsharpDefaultExample
    {
        /// <summary>
        /// Defines the entry point of the application.
        /// </summary>
        static void Main()
        {
            var testOne = default(StringComparer);
            var testTwo = default(int);
            var testThree = default(bool);
            var testFour = default(MyClass);
            var testFive = default(long);

            Console.WriteLine(testOne);
            Console.WriteLine(testTwo);
            Console.WriteLine(testThree);
            Console.WriteLine(testFour);
            Console.WriteLine(testFive);

            Console.ReadKey();
        }
    }

    /// <summary>
    /// Simple class for demonstration
    /// </summary>
    public class MyClass
    {
    }
}

Returns:

0
False

0

Leave a Reply

Your email address will not be published. Required fields are marked *