What's the advantages to use IEnumerable over List? For example I have a Employee class and a collection of employee objects, if I want to iterate each employee, I can either use:
List employees = new List() { new Employee(...),...}
foreach (Employee emp in employees)
{
Console.WriteLine(emp.Name);
}
or I can use Ienumerable as :
IEnumerable employees = new List() { new Employee(...),...}
then use foreach loop.
Both of them achieve same goal, so why we sometimes prefer to use IEnumerable over List?
No comments:
Post a Comment