为什么我们可以在struct中使用静态循环引用而不是实例类型循环引用?
- struct C
- {
- //following line is not allowed. Compile time error.
- // it's a non static circular reference.
- public C c1;
- //But this line compiles fine.
- //static circular reference.
- public static C c2;
- }
解决方法
非静态引用失败是因为您试图使结构成为其自身的一部分,从而导致循环引用.
静态声明是有效的,因为c2不是结构本身的一部分;每当你声明例如C foo,c2不影响foo的大小.