Open In App

Introduction to Built-in Data Structures in C#

Last Updated : 19 Sep, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

In the C#, we have data structures like a dictionary, array, stack, hashtable, queue, Linkedlist, etc. Each data structure allows us to play with the collection of data with different principles.

Let’s see what inbuilt Data Structures C# offers us:

In-Built Data Structure

Internal Implementation

Static or Dynamic

C# Arrays:

System.Array base class.

Static

C# Stack:

It is based on an internal array-like structure that can dynamically change in size.

Dynamic

C# Queue:

An array (also known as a circular buffer or ring buffer) with a front and rear pointer.

Dynamic

C# Hashtable:

An array of “buckets” (also known as “slots”).

Dynamic

C# Dictionary:

Uses a hash table as its internal data structure for efficient storage and retrieval of key-value pairs.

Dynamic

C# Linked List:

Implement a doubly-linked list.

Dynamic

C# Arrays:

An array in C# is a collection of elements of the same type stored in the exact memory location. For example, in C#, an array is an object of base type “System.Array”. The array index in C# starts at 0. In a C# array, you can only store a fixed number of elements.

C# Stack:

Stack is a special type of collection that stores elements in LIFO style (Last In First Out). C# includes the generic Stack<T> and non-generic Stack collection classes. It is recommended to use the generic Stack<T> collection.

C# Queue:

A Queue in C# represents a first-in, first-out (FIFO) collection of objects. An example of a queue is a line of people waiting.
The Queue<T> class in the System.Collection.Generic namespace represents a queue in C#, where T specifies the type of elements in the queue.

C# Hashtable:

A Hashtable is a collection of key/value pairs that are arranged based on the hash code of the key. Or in other words, a Hashtable is used to create a collection which uses a hash table for storage. It generally optimized the lookup by calculating the hash code of every key and store into another basket automatically and when you accessing the value from the hashtable at that time it matches the hashcode with the specified key. It is the non-generic type of collection which is defined in System.Collections namespace. 

C# Dictionary:

In C#, Dictionary is a generic collection which is generally used to store key/value pairs. The working of Dictionary is quite similar to the non-generic hashtable. The advantage of Dictionary is, it is generic type. Dictionary is defined under System.Collections.Generic namespace. It is dynamic in nature means the size of the dictionary is grows according to the need.

C# Linked List:

LinkedList is a linear data structure which stores element in the non-contiguous location. The elements in a linked list are linked with each other using pointers. Or in other words, LinkedList consists of nodes where each node contains a data field and a reference(link) to the next node in the list. In C#, LinkedList is the generic type of collection which is defined in System.Collections.Generic namespace.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads