Non-read only alternative to anonymous types

No, you’ll have to create your own class or struct to do this (preferrably a class if you want it to be mutable – mutable structs are horrible).

If you don’t care about Equals/ToString/GetHashCode implementations, that’s pretty easy:

public class MyClass {
    public bool Foo { get; set; }
    public bool Bar { get; set; }
}

(I’d still use properties rather than fields, for various reasons.)

Personally I usually find myself wanting an immutable type which I can pass between methods etc – I want a named version of the existing anonymous type feature…

Leave a Comment