C# SortedList Tutorial with Examples

C# SortedList Tutorial with Examples

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

Introduction: SortedList in C#.Net

In this post, we will learn about SortedList in C#.Net with an example.The SortedList<> class represents a collection of key/value pairs that are sorted by key. A sorted list is a combination of an array and a hash table.

READ :  Vue JS carousel image Slider Example - Vuejs Image Slider

Methods :

1. Add(object key, object value)

This method is used to

2. Remove(object key)

This method is used to removes element with the specified key.

1. RemoveAt(int index)

This method is used to removes element at the specified index.

1. Contains(object key)

This method is used to checks whether specified key exists in SortedList.

1. Clear()

This method is used to removes all the elements from SortedList.

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

[php]
using System;
using System.Collections;

namespace ConsoleDemo
{
class Program
{
static void Main(string[] args)
{
SortedList _SiteList = new SortedList();

_SiteList.Add(“001”, “pakainfo.Com”);
_SiteList.Add(“002”, “infinityknow.com”);
_SiteList.Add(“003”, “W3pSchool.Com”);

READ :  Laravel 6 Get Current User Example

foreach (string k in _SiteList.Keys)
{
Console.WriteLine(k + “: ” + _SiteList[k]);
}
Console.ReadKey();
}
}
}
[/php]

Read :

Summary

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

I hope you get an idea about C# SortedList Class.
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.

Leave a Comment