Use a property with a backing field:
struct MyStruct
{
private const int MIN_VALUE = 1200;
private const int MAX_VALUE = 1599;
private int x;
public int X
{
get { return x + MIN_VALUE; }
set
{
if(value > MAX_VALUE)
x = MAX_VALUE;
else if(value < MIN_VALUE)
x = MIN_VALUE;
else
x = value;
x -= MIN_VALUE;
}
}
// constructor is not really needed anymore, but can still be added
}
I combined the property with my setter and Damien_The_Unbeliever's getter to get the initial state of x
right. I also agree with Tim about constants for the "magic numbers" and added that too. So please give this two also credit for "my answer".
Also as DatVM already said: Public fields/properties should start with a capital letter according to the common C# naming guidlines. This also enalbes you to use the same name for the backing field, but starting with a small letter (I personally do NOT like the ugly _)...
And last but not least: Please read rexcfnghk's answer, even if it is not really an answer, as he is also absolutely correct.