why can we have a static circular reference in struct but not a instance type circular reference ?
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;
}
The non-static reference fails because you're trying to make the structure a part of itself, which results in the circular reference.
The static declaration works because c2
is not a part of the structure itself; whenever you declare e.g. C foo
, c2
does not affect the size of foo
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With