You are here:

C#/accessing member data of an iterator

Advertisement


Question
I'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

Answer
Hi

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

C#

All Answers


Answers by Expert:


Ask Experts

Volunteer


Srini Nagarajan

Expertise

can answer any kind of questions in ASP.NET, C#, VB.NET, ASP, SharePoint 2007, Coldfusion, Powerbuilder 7.00 / 8.00, JAVA servlets, MS SQL 2000 / MSSQL7, Sybase

Experience

Contact me if you need any custom development on ASP.NET, ASP, Coldfusion, Powerbuilder

©2012 About.com, a part of The New York Times Company. All rights reserved.