2 ms·
It's not like MS wants to make it easy to use a functional or procedural paradigm. I tried to bind an IConfiguration section to a record but I couldn't since i
by DeathArrow 5y ago
It's not like MS wants to make it easy to use a functional or procedural paradigm.
I tried to bind an IConfiguration section to a record but I couldn't since in condensed form a record lacks a default constructor. So I had to write a class like record and add Init to each property to make them immutable.
- zigzag312 5y agoI think you can add default constructor manually. Something like this: public record Foo(int X, int Y) { public Foo():this(0,0) { } } Or make all parameters optional public record Foo(int X = 0, int Y = 0);
- DeathArrow 5y agoTried with public Record Foo(int x = default, int y = default); and it still complained about missing a constructor. I didn't try to add an constructor like you suggested, it's still shorter than defining all members.