![]() | |
![]() |
| | Thread Tools | Search this Thread | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
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? |
#3
| |||
| |||
|
|
[...] 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? |
#4
| |||
| |||
|
|
PS - indexers don't seem to work for me. This is an array member in a class that has to exectute another member function. If I nest it so the indexer works, I can't reference the class function SetBounds.... |
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
| |