Hello friend,
Questions are as follows:
private void button1_Click(object sender, EventArgs e){
Listlist = new List (); for (int i = 1; i <= 10; i++) list.Add(i);IEnumerableenumer = list; foreach (int item in enumer){textBox1.Text += item.ToString() + "|";}IEnumeratorenumer2 = list.GetEnumerator(); while (enumer2.MoveNext()){textBox2.Text += enumer2.Current.ToString() + "|";}IEnumeratorenumer3 = list.GetEnumerator(); foreach (int item in enumer3) // Try use foreach,but compilation errors in here.{textBox3.Text += item.ToString() + "|";}
}
Thanks.

VulpesPosted Jan 2, 2015, 10:38 AM
An enumerator for this purpose is any object which has a Current property and a MoveNext() method. The object doesn't necessarily have to implement IEnumerator or IEnumerator
Here's an example of such an object:
Ken HPosted Jan 3, 2015, 1:09 AM
Thank for you. :)
Ken HPosted Jan 2, 2015, 10:04 AM
If the object does not inherit IEnumerable can be used 'foreach'?
Does that mean that all objects inherit the IEnumerator
I am still confused IEnumerable and IEnumerator.
VulpesPosted Jan 2, 2015, 7:22 AM
Michal HabalcikPosted Jan 2, 2015, 4:27 AM
Ken HPosted Jan 2, 2015, 4:20 AM
Michal HabalcikPosted Jan 2, 2015, 4:04 AM
why not just:
foreach (var item in list)
{
textBox3.Text += item.ToString() + "|";
}