C# Sorted Dictionary Tutorial with Examples

C# Sorted Dictionary Tutorial with Examples

Today, We want to share with you C# Sorted Dictionary Tutorial with Examples.
In this post we will show you Sorted Dictionary in C#.Net with example and description, hear for we will give you demo and example for implement.
In this post, we will learn about C# SortedDictionary Examples with an example.

Introduction: Sorted Dictionary in C#.Net

In this post, we will learn about Sorted Dictionary in C#.Net with an example. SortedDictionary keeps its keys always sorted. It allows you to avoid sorting the keys on your own.It has advantages if you want a sorted lookup table.

READ :  Dropbox API - Laravel Oauth Dropbox File Upload Steps

Methods:

1. Add()

This method is used to add the key/value pair to the dictionary.

2. ContainKey()

This method is used to determines whether the SortedDictionary<TKey, TValue> contains an element with the specified key or not. If yes then return true else return false.

3. ContainValue()

This method is used to determines whether the SortedDictionary<TKey, TValue> contains an element with the specified value or not and returns true if the value exists.

4. Remove()

This method is used to removes the element with the specified key from the SortedDictionary<TKey, TValue>.

5. Clear()

This method is used to removes all elements from the SortedDictionary<TKey, TValue>.

READ :  C# SortedList Tutorial with Examples

Now, Create Console Application in Visual Studio and write below line of code.

using System;
using System.Collections.Generic;

namespace ConsoleDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            // Create a SortedDictionary with site as a string and Int16 value pair
            SortedDictionary SiteList = new SortedDictionary();
            SiteList.Add("DotNetK.com", 10);
            SiteList.Add("Live24u.com", 30);
            SiteList.Add("w3school.com", 15);

            // Read all data
            Console.WriteLine("Site List");

            foreach (KeyValuePair site in SiteList)
            {
                Console.WriteLine("Key: {0}, Value: {1}",
                    site.Key, site.Value);
            }
            Console.ReadKey();
        }
    }   
}

Read :

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about ASP.NET C# uses for SortedList vs. SortedDictionary vs. Dictionary.
I would like to have feedback on my Infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

READ :  Angular Call Function on Page Load Example
https://pakainfo.com/

Add a Comment

Your email address will not be published. Required fields are marked *