也许我误解了只读结构的概念,但我认为这段代码不应该编译:
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);
}
}
(我使用的是 C# 7.3。)我错过了什么吗?
慕姐8265434
狐的传说
相关分类