C#属性的默认值

示例

可以使用初始化程序(C#6)设置默认值

public class Name 
{
    public string First { get; set; } = "James";
    public string Last { get; set; } = "Smith";
}

如果它是只读的,则可以返回如下值:

  public class Name 
  {
      public string First => "James";
      public string Last => "Smith";
  }