Data Structures 

list of datastructures in c#

In C#, there are various data structures available, each serving different purposes and optimizing specific types of data operations. Here's a list of some of the commonly used data structures in C#:

Collections

Special Collections

Specialized Data Structures


SortedList in C# is a data structure that stores key-value pairs in a sorted order based on the keys. It's part of the System.Collections.Generic namespace and combines the features of a dictionary and a sorted list. Here are the main features and benefits of using SortedList:

Key Features of SortedList:

Syntax and Example:

Here’s how you can create and use a SortedList:

Declaration and Initialization:

csharp

using System;

using System.Collections.Generic;


class Program

{

    static void Main()

    {

        // Create a new SortedList

        SortedList<int, string> sortedList = new SortedList<int, string>();


        // Add elements to the SortedList

        sortedList.Add(3, "Three");

        sortedList.Add(1, "One");

        sortedList.Add(2, "Two");


        // Display the elements in sorted order

        foreach (KeyValuePair<int, string> kvp in sortedList)

        {

            Console.WriteLine($"Key: {kvp.Key}, Value: {kvp.Value}");

        }

    }

}