bpayne111 Posted March 7, 2003 Posted March 7, 2003 Anyone up for explaining IEnumerable and IEnumerator? I'm familiar with Interfaces, and i slightly understand the purpose of these 2 in particular. The help files have left me pretty confused. A tiny snippit of code would be wonderful. Thanks Quote i'm not lazy i'm just resting before i get tired.
*Gurus* divil Posted March 7, 2003 *Gurus* Posted March 7, 2003 The IEnumerable interface is something that a class implements when it wants to be enumerator. It forces the class to expose a GetEnumerator function, which will return a class implementing the IEnumerator interface. Any class implementing that second interface must expose a property reflecting the current item in the enumeration, and a method for moving forward and moving to the start of the iteration. You don't always see these interfaces, but when you use a For Each statement (foreach in C#) it is using them under the hood. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bpayne111 Posted March 8, 2003 Author Posted March 8, 2003 yes actually that is the part that i understood, i do not understand how i'm supposed to implement it so that it works correctly with a for each statement in other words i understand the concept but not the actual coding of the interface itself care to explain a lil more? thanks Quote i'm not lazy i'm just resting before i get tired.
bpayne111 Posted March 8, 2003 Author Posted March 8, 2003 ok so i've done some more research at msdn so i'd like to know if i got this right... if i create a class that implements IEnumerable and then define my own movenext method...When i use a For Each... Next statement it will work according to how i defined it in MoveNext? so hypethetically i could actually make it only enumerate through 1 item of a list if i'd like? hmmm interesting let me know ps divil... one of these days i'm gonna help you lol thanks Quote i'm not lazy i'm just resting before i get tired.
*Gurus* divil Posted March 8, 2003 *Gurus* Posted March 8, 2003 Yeah, something like that. Truth be told I've never implemented an enumerator manually, all my collections inherit from CollectionBase so it hasn't been a concern. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bpayne111 Posted March 8, 2003 Author Posted March 8, 2003 yes i was about to guess that lol thanks for your help Quote i'm not lazy i'm just resting before i get tired.
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.