Intruduction :

In this blog we can what is Non-Generic Collections in C#.

What is Non-Generic Collections in C#?

Different datatypes are represented in elements of non-generic collections. The non-generic collections are as follows: BitArray, ArrayList. It represents an ordered group of objects that may each be separately indexed. An alternative to an array is an ArrayList.

Non-generic collections in C# are those that support storing data components of any type. Here are a few typical C# non-generic collections.

  1. ArrayList
  2. Stack
  3. Queue
  4. BitArray
  5. Hashtable
  6. SortedList

ArrayList :

Similar to an array, an arraylist stores objects of any kind. The ArrayList expands naturally, thus there is no need to specify the size of it like there would be with an array.ArrayList automatically resizes as elements are added or removed, making it an efficient collection for changing data sets.
Stack:
Values are stored in a stack using the LIFO (Last In First Out) method. It offers the Push() method for adding items as well as the Pop() and Peek() methods for retrieving values. Generic and non-generic Stack are both supported in C#.A stack can be used to reverse the order of elements or to implement undo functionality in a program.

Queue :

Values are kept in a queue using the FIFO method (First In First Out). The order in which the values were inserted is preserved. It offers the Enqueue() and Dequeue() methods to add and remove values from the collection, respectively. Generic and non-generic Queue are available in C#. A queue can be used to implement a task queue or to implement a breadth-first search algorithm.

BitArray :

BitArray controls a small array of bit values that are expressed as Booleans, where true denotes a on bit (1) and false denotes an off bit (0).BitArray can be used to represent a set of flags or to implement a compact representation of binary data.

Hashtable :

Hashtables are used to hold key-value pairs. It fetches the values by comparing the keys’ hash values.Hashtable is ideal for lookups where the key is used to index the data.

SortedList :

SortedList is a collection of key-value pairs. By default, it arranges elements in ascending order of key. SortedList collections in C# are both generic and non-generic.

For any Help or Queries Contact us on info@crmonce.com or +918096556344