How to declare a C# Record Type?

前端 未结 6 1629
日久生厌
日久生厌 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:04

    There is a way if you're looking for record-like, lazy way of implementing constructors using currently available C# 7 functionality:

    class Lazystructor
    {
        int a;
        float b;
        WebClient c;
    
        public Lazystructor(int a, float b, WebClient c)
            =>  (this.a, this.b, this.c) = (a, b, c);
    }
    

    A bit of consideration if you're using this on a performance-sensitive scenario, as it's a process of ValueTuple creation and extraction.

提交回复
热议问题