Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

i'm not lazy i'm just resting before i get tired.
  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

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

i'm not lazy i'm just resting before i get tired.
Posted

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

i'm not lazy i'm just resting before i get tired.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...