G
Guest
That didn't come out right, but what I mean is something like:
struct X
{
private int x ;
public readonly X MinValue ;
static X() { MinValue = new X ( 0 ) ; }
public X
(
int x
)
{
this.x = x ;
}
}
The struct has a readonly field to contain the MinValue, and the type of
that field has to be that the struct that's being defined. Ergo I get
"...causes a cycle in the struct layout". I.e. I can't construct the static
value until after the static value is constructed.
So I'm left with making a read-only property for it, which works, but takes
more processing each time one of these "constants" is accessed.
Is there something I'm missing?
Another solution would be to store the minvalue in a private readonly
_object_ and have a property that simply casts it back, that would cut down
the processing.
Any thoughts?
struct X
{
private int x ;
public readonly X MinValue ;
static X() { MinValue = new X ( 0 ) ; }
public X
(
int x
)
{
this.x = x ;
}
}
The struct has a readonly field to contain the MinValue, and the type of
that field has to be that the struct that's being defined. Ergo I get
"...causes a cycle in the struct layout". I.e. I can't construct the static
value until after the static value is constructed.
So I'm left with making a read-only property for it, which works, but takes
more processing each time one of these "constants" is accessed.
Is there something I'm missing?
Another solution would be to store the minvalue in a private readonly
_object_ and have a property that simply casts it back, that would cut down
the processing.
Any thoughts?