KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Possible Duplicate: How do foreach loops work in C#? I've been searching the internet and I'm having trouble finding any answers as to what's really going on behind the scenes with the foreach loop in C#. I know this question doesn't really pertain to actually coding but its bothering me. I'm pretty new to OO programming and especially interfaces. I understand they are contracts and I understand how IEnumerable and IEnumerator work - or so I think. I've been reading this article on MSDN: IEnumerable Interface I understand how everything is set up. I'm a little unclear though in the Main loop how the foreach knows to itterate through all the values in _people . How does it know this? How does it keep track of Current by just calling return new PeopleEnum(_people); ? EDIT : I don't see how this is an exact duplicate. Yes its similar grounds and the same question is being asked but we are looking for different answers or the answer I wanted was not discussed in the previous question. A foreach loop like foreach(int i in obj) {...} kinda equates to ... is "kinda" not the answer I'm looking for.
Tags (comma-separated)
Save Edits
Cancel