How to declare a C# Record Type?

前端 未结 6 1551
日久生厌
日久生厌 2021-02-06 23:22

I read on a blog that C# 7 will feature record types

class studentInfo(string StudentFName, string StudentMName, string StudentLName);

However

6条回答
  •  心在旅途
    2021-02-07 00:02

    Update:

    C# 9 now contains record types.

    public record Person
    {
        public string LastName { get; }
        public string FirstName { get; }
    
        public Person(string first, string last) => (FirstName, LastName) = (first, last);
    }
    

    Old answer:

    Record types are not (yet) implemented in C#. See the proposal in the official GitHub repository:

    https://github.com/dotnet/csharplang/blob/master/proposals/records.md

    Discuss or vote at https://github.com/dotnet/csharplang/issues/39

提交回复
热议问题