C# IEnumerable vs IEnumerator
IEnumerable vs. IEnumerator IEnumerable vs. IEnumerator Both are uses to loop through lists. 'For each' uses internally getEnumerator() to iterating to objects. Differences: - IEnumerable uses IEnumerator internally. IEnumerable does not remember its cursor position where as IEnumerator remembers it. For example you are writing two functions to list some details , one should list the years less than 2000 and other function should show the years greater than 2000. I Enumerator will support it by keeping its current cursor position (current state). Example:- List Year = new List (); Year.Add(2000); Year.Add(2001); Year.Add(2002); IEnumerable getYear = (IEnumerable )Year; foreach (int i in getYear) { txtYeas.Text += i.ToString() + ","; } IEnumerator getsYear = Year.GetEnumerator(); while (getsYear.MoveNext()) { txtYeas.Text += getsYear.Current.ToString() + ","; } IComparable vs. IComparer Use...