Assign variable to its default value - CSharp Language Basics

CSharp examples for Language Basics:default

Description

Assign variable to its default value


using System;
using System.Collections.Generic;

public class ThingOfDefaults
{

    public int Population;
    public DateTime When;
    public string Name;
    public List<Person> People;

    public ThingOfDefaults()
    {
        Population = default; // C# 7.1 and later
        When = default;
        Name = default;
        People = default;
    }
}

Related Tutorials