List li = new List();
Animals n = new Animals();
n.Cat = 1;
n.Dog = 2;
n.tiger = 3;
li.Add(n);
Animals n1 = new Animals();
n1.Cat = 2;
n1.Dog = 2;
n1.tiger = 3;
li.Add(n1);
IEnumerable test= li;
foreach (var item in test)
{
Console.WriteLine(item.Cat);
}
foreach (var item in li)
{
Console.WriteLine(item.Cat);
}
Console.Read();
What is the difference between Ienumerable and list.List implements the interface Ienumerable.so it Includes all methods of IEnumerable.
Where should I use IEnumerable<> And List<> respectively.
Please Explain me the difference with an example.
Jignesh TrivediPosted Jul 15, 2013, 11:01 PM
hi,
List is also implements from IEnumerable interface. IEnumerable is an interface. List is a class that defines a generic collection
IEnumerable doesn't allow random access, where as List does allow random access using integral index.
In term of performance, iterating values from IEnumerable is much faster than iterating values from a List.
hope this will help you.
VulpesPosted Jul 15, 2013, 10:33 AM
Iftikar HussainPosted Jul 15, 2013, 8:43 AM
Please refer the below link
http://stackoverflow.com/questions/3628425/ienumerable-vs-list-what-to-use-how-do-they-work
Regards,
Iftikar