System.Collections.Generic.IEnumerable<T>

Added in .NET 2.0
Arrays automatically implement IEnumerable<T> where T is the member type of the array.


public interface IEnumerable<T> : IEnumerable 
{
   IEnumerator<T> GetEnumerator();
}

class MyList2<T> : IEnumerable<T> 
{
}

MyList2<string> mylist;

mylist = new MyList2<string>();
mylist.Add("Monday");
mylist.Add("Tuesday");

foreach (string s in mylist)
{
   System.ConsoleWriteLine(s);
}

Generic Collection - IEnumerable<T>
Enumerating a generic collection class

System.Collections.Generic.List<string> mylist; 

mylist = new System.Collections.Generic.List<string>();
mylist.Add("Monday");
mylist.Add("Tuesday");

foreach (string s in mylist)
{
   System.ConsoleWriteLine(s);
}


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext