C#/accessing member data of an iterator
Expert: Srini Nagarajan - 2/7/2005
QuestionI'm having trouble discovering how to access data members of objects pointed to by the iterator created from the IEnumerator class.
Here is a copy of my function so far:
public void Translate(int dx, int dy)
{
myX = myX + dx;
myY = myY + dy;
System.Collections.IEnumerator myEnumerator = myAL.GetEnumerator();
while (myEnumerator.MoveNext())
{
// myEnumerator.Current -> Top += dy; // does not work
// myEnumerator.Current.Left += dx; // does not work
}
The Translate function (method) is used to update the x/y coordinates of an object or composition. For the composition class the corresponding coordinates of the objects contained within would be updated by this function as well.
I need to know how to access member data of the object pointed to by the iterator so that I can update the data according to the position of the x/y cordinates of the composite. In c++ I would be using -> or * to dereference the pointer and access object member data.
I am more used to c++ where iterators are actually smart pointers (classes that overloaded * and -> operators) in c# there are no real pointers that I know of. So I know what I wnat to do but it comes down to a syntax issue where I dont know how to get it done.
The purpose behind this project is to create a "composete" structure that contains shape objects that directly relate to the position of the containing composite class.
as described here:
http://www.informit.com/articles/article.asp?p=30211
However I need to access the objects contained in the composete so that I can update the corrisponding position of various shape classes in relation to the composite.
I am using MS visual studio 2005 beta refresh
Any help or point in the right direction would be great! Let me know if you need any more information.
Thanks
Nathan Holmes
AnswerHi
I am sorry for the delay in reply, I was away from my email..
The problem with C# is not a pointer based.. Here is the site talks about the composite Patterns with sample
http://www.codeproject.com/csharp/csdespat_2.asp
http://msdn.microsoft.com/msdnmag/issues/01/08/cutting/default.aspx
If i find anything I'll update you
Happy Programming!!
-Srini