Understanding Collections and Collections Interfaces
A collection is a set of related objects. Unlike arrays, a collection can grow and shrink dynamically as the number of objects added or deleted. A collection is a class, so you must declare a new collection before you can add elements to that collection.
The .NET Framework provides various collections like ArrayList, HashTable , SortedList, Stack and Queue etc. All these collections are exists in System.Collections namespace.
All of the collection types use some common interfaces. These common interfaces define the basic functionality for each collection class. The key collections interfaces are – IEnumerable, ICollection, IDictionary and IList.
IEnumerable acts as a base interface for all the collection types that is extended by ICollection. ICollection is further extended by IDictionary and IList.
All collections interfaces are not implemented by all the collections. It depends on collection nature.
For example, IDictionary interface would be implemented by only those collection classes which support key/value pairs, like HasTable and SortedList etc.
What do you think?
I hope you will enjoy the collections and collections interfaces while programming with C#. I would like to have feedback from my blog readers. Your valuable feedback, question, or comments about this article are always welcome.
Take our free skill tests to evaluate your skill!
In less than 5 minutes, with our skill test, you can identify your knowledge gaps and strengths.