Can anyone elaborate on IList and ICollection. And also, When and where do we use IList or ICollection
Asked
Active
Viewed 3,904 times
0
-
13See the answers in: [IList vs ICollection vs Collection](http://stackoverflow.com/questions/9855693/ilist-vs-icollection-vs-collection) – cbr Nov 11 '15 at 01:12
-
@cubrr so, it isnt a dupe, or we should flag/close as dupe? – D. Ben Knoble Nov 11 '15 at 02:49
1 Answers
9
IList
implements ICollection
and IEnumerable
. In addition it provides method definitions for adding and removing elements and to clear the collection. It also provides methods for handling the positioning of the elements within the collection. It also provides an object indexer to allow the user to access the collection with square brackets like:
myList[elementIndex]
reference: Claudio Bernasconi's article about IList and ICollection

Sebastian 506563
- 6,980
- 3
- 31
- 56
-
That's confusing ; you say in substance that IList is ICollection with random-order and just after to use IList for ordered things. – Sehnsucht Nov 11 '15 at 01:38
-
-
-
-
@Sehnsucht random order = 1,2,4,0,6,11 , non random order = 0,1,2,4,6,11, sorry i am not fluent – Sebastian 506563 Nov 11 '15 at 01:52
-
1Both have `.Count`. And `.Add` and `.Remove` come from `IList`. `IList` is ordered and can be accessed by Index while `ICollection` is not. `IList` extends `ICollection`. So almost everything is the opposite of your answer – Martin Schneider Apr 19 '18 at 19:55
-
MA-Maddin you are absolutely right in 2015 I wasn't experienced enough in english and in C# to answer this in a correct way. I have fixed everything. Sorry – Sebastian 506563 Apr 20 '18 at 11:58