在关键字“数据”或“记录”中声明C#9.0中的记录?

时间:2020-11-10 20:19:34

标签: c# c#-9.0

是否在关键字数据中使用?

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; }
}

1 个答案:

答案 0 :(得分:1)

他们更改record

定义

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

现在仅有效记录定义。

相关问题