This project is read-only.
7
Vote

Provide Immutable non anonymous RecordType

description

We already have anonymous types in C# which are immutable and implement IEquatable and IStructuralEquatable. However because they are anonymous it is impossible to return them from a non generic method.

Perhapps a keyword "record" could be added that behaves similarly to "class" but by default all fields are readonly and properties are not allowed to have setters.

comments

MgSam wrote May 16, 2014 at 3:23 PM

Relevant discussion: https://roslyn.codeplex.com/discussions/543522#post1245999

The only thing I'd add here is that I'd rather just make it possible to make these immutable types with existing keywords rather than add new ones: struct Foo(int Bar); and class Foo(int Bar); make the immutable properties and automatically implement Equals and GetHashCode.

majnu wrote Nov 4, 2014 at 1:20 PM

Functional programming rules. Also in VB.NET!

nmgafter wrote Nov 4, 2014 at 10:10 PM

This is already being considered for the next major revisions of C# and VB.