Possible Duplicate:
What's the difference between IEnumerable and Array, IList and List?
What's the difference between the above two?
Possible Duplicate:
What's the difference between IEnumerable and Array, IList and List?
What's the difference between the above two?
A List<string>
is a concrete implementation of IEnumerable<string>
. The difference is that IEnumerable<string>
is merely a sequence of string
but a List<string>
is indexable by an int
index, can be added to and removed from and have items inserted at a particular index.
Basically, the interface IEnumerable<string>
lets you stream the string
in the sequence but List<string>
lets you do this as well as modify and access the items in the lists in specific ways. An IEnumerable<string>
is general sequence of string
that can be iterated but doesn't allow random access. A List<string>
is a specific random-access variable-size collection.
different.
IEnumerable enables you to iterate through the collection using a for-each loop.
And IEnumerable just have method GetEnumerator.
And List it implement many interface like IEnumerable, Ilist, etc. So many function in List.
In performance IEnumerable faster than List.
IEnumerable<T>
is an interface. It must be implemented.
List<T>
is one implementation of IEnumerable<T>
One is an interface: http://msdn.microsoft.com/en-us/library/9eekhta0.aspx
The other is a class that implements that interface: http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx
Also, List is an array that grows when you add elements to it, while IEnumerable allows implementers to be used in a foreach.
The first is a concrete List
of strings, the other is any class implementing IEnumerable<string>