Recently I got a little bit confused by readonly declaration of struct with comparison with classes.
Consider the following:
public class TheClass
{
public readonly int X;
public readonly int Y;
public readonly object A;
public TheClass(int x, int y, object a) => (X, Y, A) = (x, y, a);
}
public readonly struct TheStruct
{
public readonly int X;
public readonly int Y;
public readonly object A;
public TheStruct(int x, int y, object a) => (X, Y, A) = (x, y, a);
}
My question is - why there is no possibility to declare TheClass as public readonly class TheClass? That would force other fields to be declared readonly and it's easier to read as well as understand the intent of the author.