【问题标题】:declaration the records in C# 9.0 in keyword "data" or "records"?在关键字“data”或“records”中声明 C# 9.0 中的记录?
【发布时间】:2020-11-10 20:19:34
【问题描述】:

在关键字数据中使用吗?

public data class Person
{
    public string FirstName { get; init; }
    public string LastName { get; init; }
}

或更改记录?

public record class Person
{
    public string FirstName { get; init; }
    public string LastName { get; init; }
}

【问题讨论】:

    标签: c# c#-9.0


    【解决方案1】:

    他们更改record

    定义

    public record class Person
    {
        public string FirstName { get; init; }
        public string LastName { get; init; }
    }
    

    现在是唯一有效的记录定义。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-09-06
      相关资源
      最近更新 更多