[ACCEPTED]-What's the difference between List<string> and IEnumerable<String>?-.net

Accepted answer
Score: 75

A List<string> is a concrete implementation of IEnumerable<string>. The 11 difference is that IEnumerable<string> is merely a sequence 10 of string but a List<string> is indexable by an int index, can 9 be added to and removed from and have items 8 inserted at a particular index.

Basically, the 7 interface IEnumerable<string> lets you stream the string in the sequence 6 but List<string> lets you do this as well as modify 5 and access the items in the lists in specific 4 ways. An IEnumerable<string> is general sequence of string that can 3 be iterated but doesn't allow random access. A 2 List<string> is a specific random-access variable-size 1 collection.

Score: 11

different.

IEnumerable enables you to iterate 5 through the collection using a for-each 4 loop.

And IEnumerable just have method GetEnumerator.

And 3 List it implement many interface like IEnumerable, Ilist, etc. So 2 many function in List.

In performance IEnumerable 1 faster than List.

Score: 4

IEnumerable<T> is an interface. It must be implemented.

List<T> is 1 one implementation of IEnumerable<T>

Score: 2

One is an interface: http://msdn.microsoft.com/en-us/library/9eekhta0.aspx

The other is a class 4 that implements that interface: http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx

Also, List 3 is an array that grows when you add elements 2 to it, while IEnumerable allows implementers 1 to be used in a foreach.

Score: 2

The first is a concrete List of strings, the 1 other is any class implementing IEnumerable<string>

More Related questions