5
如何在C#中的不可变对象之间建立循环引用?
在下面的代码示例中,我们有一个表示房间的不可变对象的类。北,南,东和西代表进入其他房间的出口。 public sealed class Room { public Room(string name, Room northExit, Room southExit, Room eastExit, Room westExit) { this.Name = name; this.North = northExit; this.South = southExit; this.East = eastExit; this.West = westExit; } public string Name { get; } public Room North { get; } public Room South { …