Public · Protected · Private
IEnumerable ,IEnumerator
Type: Public  |  Created: 2012-06-14  |  Frozen: Yes
« Previous Public Blog Next Public Blog »
Comments
  • public interface IEnumerator { bool MoveNext (); object Current { get;} void Reset (); } This interface just supports navigation across items -- Iteration You can implement it across your objects as below... class staff : IEnumerable { private Human[] employees = new Human[4]; public staff() { employees[0] = new Human("bob"); employees[1] = new Human("chris"); employees[2] = new Human("jennifer"); employees[3] = new Human("Brian"); } public IEnumerator GetEnumerator() { return employees.GetEnumerator(); } } class Human { public string Name{get;set;} public Human(string name) { Name = name; } } Here is navigation.... staff office = new staff(); foreach (Human h in office ) { MessageBox.Show(h.Name); }
    2012-06-14 01:42
  • public IEnumerator GetEnumerator() { // this can be replaced // return employees.GetEnumerator(); foreach (Human c in employees) { yield return c; } }
    2012-06-14 02:32
This blog is frozen. No new comments or edits allowed.