B
bern11
I have a class with a 3 point array which I want to protect through
encapsulation. Unfortunately, the following does not do what I want:
private PointF[] vtx = new PointF[3];
public PointF[] Vtx
{
get { return vtx; }
set
{
vtx = value;
SetBounds();
}
}
I want to call the 'set' member whenever an individual array element is
called. As it is, this statement:
myObject.Vtx[0] = 10;
does not call the 'set' accessor, even though a statement such as this
calls the 'get' accessor:
x = myObject.Vtx[0];
So, how do I encapsulate access to individual members of a member array?
In hindsight, it is clear that my declaration is screwed up, since the
'set' declaration would only work if value were a 3 point array, not a
single value. But, how to fix it?
encapsulation. Unfortunately, the following does not do what I want:
private PointF[] vtx = new PointF[3];
public PointF[] Vtx
{
get { return vtx; }
set
{
vtx = value;
SetBounds();
}
}
I want to call the 'set' member whenever an individual array element is
called. As it is, this statement:
myObject.Vtx[0] = 10;
does not call the 'set' accessor, even though a statement such as this
calls the 'get' accessor:
x = myObject.Vtx[0];
So, how do I encapsulate access to individual members of a member array?
In hindsight, it is clear that my declaration is screwed up, since the
'set' declaration would only work if value were a 3 point array, not a
single value. But, how to fix it?