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

你可能感兴趣的:(Initializing nested object properties z)