Collections and non-generics
On day two, we learned about arrays, which are of fixed size, and you can use these for strongly typed list objects. But what about if we want to use or organize these objects into other data structures such as queues, lists, stacks, and so on? All these we can achieve with the use of collections (System.Collections
).
There are various ways to play with data (storage and retrieval) with the use of collections. The following are the main collection classes we can use.
Note
System.Collections.NonGeneric
(https://www.nuget.org/packages/System.Collections.NonGeneric/ ) is a NuGet package which provides all non-generic types, namely ArrayList
, HashTable
, Stack
, SortedList
, Queue
, and so on.
ArrayList
As it is an array, it contains an ordered collection of an object and can be indexed individually. As this is a non-generic class, it is available under a separate NuGet package from System.Collections.NonGeneric
. To work with the example code, you should first install this...