Common Collection Interfaces in C#: A Quick Summary

Cem Tuğanlı
2 min readMar 4, 2023

--

Just a small memory refresher…

IENUMERABLE:

The IEnumerable interface is used to iterate through items using a foreach loop. It has a method called GetEnumerator that returns an IEnumerator interface. The IEnumerator interface implements two methods: MoveNext() and Reset(), and also has a property called Current that returns the current item in the list.

An IEnumerable is a list or container that holds items. Each item in the IEnumerable can be iterated. Items in an IEnumerable cannot be edited, updated, or deleted; instead, a container is used to hold a list of items.

An Enumerator, which helps iterate over items in an IEnumerable, is present in it. An IEnumerable does not hold the number of items in the list; instead, iteration is required to get the number of items.

An IEnumerable supports filtering items using the where code.

ICOLLECTION:

The ICollection interface is derived from IEnumerable and provides easy access and functionality like Add(), Remove(), and Count().

ICollection is another collection type that derives from IEnumerable and provides the functionality of adding, removing, and updating items in a list. ICollection also keeps track of the number of items in it, and it is unnecessary to iterate over all the items to obtain the total number.

ICollection supports enumeration over items, filtering items, adding new items, deleting existing items, updating existing items, and getting the number of available items in the list.

It is an interface that includes properties like Count, IsSynchronized, SyncRoot, and methods like CopyTo().

ILIST:

The IList interface is an ICollection that can be accessed with an index.

IList extends ICollection. An IList can perform all the operations that are combined from IEnumerable and ICollection, such as adding or removing an item in the middle of the list.

A foreach loop or a for loop can be used to iterate over items.

It is an interface that includes properties like IsFixedSize, IsReadOnly, Indexer, and methods like Add(), Indexof(), Remove(), and RemoveAt().

A clap or a comment is much appreciated! Thank you for your time!

--

--