List-related interfaces
While developing applications in C#, you frequently use various collections, including lists. For this reason, it is worth mentioning three common interfaces:
IEnumerable
ICollection
IList
The order of them is important because IEnumerable
is the base interface for ICollection
and IList
, while ICollection
is the base interface for IList
. However, what is inside such interfaces? Let’s take a look!
IEnumerable
only provides you with a simple iteration over a collection. For this reason, it exposes the GetEnumerator
method.
The ICollection
interface adds the following methods for manipulating the collection:
Add
adds a given item to the collectionClear
removes all the items from the collectionContains
checks whether a given item exists in the collectionRemove
removes the first occurrence of a given item from the collection
It also exposes the Count
and IsReadOnly
properties, as well as the CopyTo...