Quite often, I come across the need to create small, immutable data structures. Others will probably use Tuples in these cases, but I really dislike the fact that Tuples do not read beautifully and do not express such great significance. A Value2 of int doesn't tell me anything.
An example would be to create a lookup table (Dictionary) for a combination of two properties, that is, Name and Rating .
The shortest way to make an immutable structure for these cases, which I know of, is this:
public struct Key { public string Name { get; private set; } public int Rating { get; private set; } public LolCat(string name, int rating) : this() { Name = name; Rating = rating; } }
In my opinion, there is still a lot of "syntactic fat" that I would like to get rid of. I could make it more readable when I just open the fields directly.
public struct Key { public string Name; public int Rating; }
I really like the syntax of this because there is almost no syntactic fat. The big flaw, of course, is that it is not immutable, with all its dangers.
In the ideal case, I would like to have a special type for this, with a real minimal definition, for example:
public immutable struct Key { string Name; int Rating; }
Question
Is there a real world solution that is closer to the example below to reduce the amount of syntactic fat for a very simple immutable structure?