I don’t know the correct technical terms to describe my question, so I’ll give an example:
private Point _PrivateVect = new Point();
public Point Publicvect
{
get
{
return _PrivateVect;
}
set
{
_PrivateVect = value;
}
}
The problem is that if I wanted to access Publicvect.X I get the error Cannot modify the return value of 'Publicvect' because it is not a variable. Is there a way around this? Or do I just need to do Publicvect = new Point(NewX, Publicvect.Y); forever?
Yet another reason that mutable structs are evil. One workaround is to expose the dimensions as accessors for convenience:
But other that this; yes you would need to do the
new Point(x,y)each time, sincePointis a struct. When you access it via a property you get a copy of it, so if you mutate the copy and then discard the copy, you simply lose the change.