Tag: cyclic reference

在不存在的结构布局中循环

这是我的一些代码的简化版本: public struct info { public float a, b; public info? c; public info(float a, float b, info? c = null) { this.a = a; this.b = b; this.c = c; } } 问题是错误Struct member ‘info’ causes a cycle in the struct layout. 我喜欢结构类似于值类型的行为。 我可以使用类和克隆成员函数来模拟这个,但我不明白为什么我需要。 这个错误是怎么回事? 在某些类似的情况下,递归可能会永远导致构造,但在这种情况下我无法想到它的任何方式。 下面是程序编译时应该没问题的例子。 new info(1, 2); new info(1, 2, null); […]