也许我误解了readonly结构的概念,但我认为这段代码不应该编译:
public readonly struct TwoPoints
{
private readonly Point one;
private readonly Point two;
void Foo()
{
// compiler error: Error CS1648 Members of readonly field 'TwoPoints.one'
// cannot be modified (except in a constructor or a variable initializer)
one.X = 5;
//no compiler error! (and one is not changed)
one.Offset(5, 5);
}
}
Run Code Online (Sandbox Code Playgroud)
(我正在使用C#7.3.)我错过了什么?