Initializing nested object properties z

public class Employee
{
    public Employee() 
    {
        this.Insurance = new Insurance();
    }

    // Perhaps another constructor for the name?
    public Employee(string name)
        : this()
    {
        this.Name = name;
    }

    public string Name { get; set; }
    public Insurance Insurance { get; private set; }
}

public class Insurance
{
    public int PolicyId { get; set; }
    public string PolicyName { get; set; }
}

保持内部变量被初始化。

原文地址:https://www.cnblogs.com/zeroone/p/3715343.html