Working with C# Collections
(Page 1 of 4 )
Computer programming is all about working with data. Data can be of various types and kinds and take multiple shapes and forms, but with the help of programming languages we are able to manage them seamlessly. In this article we are going to take a look at what collections are all about and how to implement them in C#. For now it’s enough if you know that under collections we understand data that’s grouped together.Fortunately, ever since its first version, the .NET Framework has given programmers a healthy amount of built-in collections classes along with numerous methods that allow us to easily manipulate the data stored within. Of course, we can also write our own collections, but throughout this article we are going to focus on what’s already been done and is ready to use. We need to understand when and how to use each.
At the beginning we will see the foundation on which each collection class lies. It’s really important to understand the interface on which they are based: IEnumerable and its ICollections extension. From the latter there are two other interfaces derived: IList and IDictionary. The collections classes which are built into the System.Collections namespaces are always implementing each of the aforementioned interfaces. However, keep in mind that there are other interfaces too (e.g.; IEnumerator, IComparer, etc.).
Before we move on, here’s a list of collection classes that are going to be covered within this brief tutorial article: Queue, Stack, BitArrays, ArrayList, StringCollection, Hashtable, SortedList, ListDictionary, StringDictionary, and so forth. There are so-called generic classes which can be reached via the System.Collections.Generic namespace, but they are strongly typed collections.
Now we are ready to move on. Once again, to eliminate all kinds of problems be sure to include the following namespaces into your test projects on which you are going to be working while reading this article: System.Collections, System.Collections.Generic, and System.Collections.Specialized. But it’s worth taking a glance over the official documentation to see which one you’re going to need.
Next: Various Collections >>
More C# Articles
More By Barzan "Tony" Antal