---
title: "What is the role of SortedList<K, V> in C#, and why are use this collection in C# explain with example?"  
description: "What is the role of SortedList<K, V> in C#, and why are use this collection in C# explain with example?"  
author: "Ethan Karla"  
published: 2021-08-27  
canonical: https://answers.mindstick.com/qa/93937/what-is-the-role-of-sortedlist-k-v-in-c-sharp-and-why-are-use-this-collection-in-c-sharp-explain-with-example  
category: "programming"  
tags: ["c#"]  
reading_time: 1 minute  

---

# What is the role of SortedList<K, V> in C#, and why are use this collection in C# explain with example?

What is the [role](https://yourviews.mindstick.com/view/85446/national-doctor-s-day-recognizing-the-indispensable-role-of-doctors-in-one-s-life) of SortedList<K, V> in C#, and why are use this [collection in C#](https://www.mindstick.com/forum/160381/how-to-add-items-to-a-list-collection-in-c-sharp) [explain](https://yourviews.mindstick.com/view/86025/content-created-for-humans-not-for-bots-explain-this-statement) with example?

## Answers

### Answer by Ravi Vishwakarma

## SortedList<K, V>

SortedList<K, V> is used for storing the value in sorted order on behalf of the key. SortedList<K, V> in a generic class of **System.Collections.Generic.**

## Syntax

SortedList<K, V> list=new SortedList<K, V>();

## Example

```
using System;
using System.Collections.Generic;
public class Program
{
 public static void Main()
 {
  SortedList<int, string> list=new SortedList<int, string>();
  list.Add(0,'Ashu');
  list.Add(2,'Shyam');
  list.Add(1,'Sunny');
  list.Add(3,'Jira');
  list.Add(4,'DB');
  Console.WriteLine('Count ; '+list.Count);
  Console.WriteLine('Capacity : '+list.Capacity);
  foreach(var item in list)
   Console.WriteLine(item + ' Key : ' + item.Key + ' Value : ' + item.Value);
 }
}
```

## Output

```
Count ; 5
Capacity : 8
[0, Ashu] Key : 0 Value : Ashu
[1, Sunny] Key : 1 Value : Sunny
[2, Shyam] Key : 2 Value : Shyam
[3, Jira] Key : 3 Value : Jira
[4, DB] Key : 4 Value : DB
```


---

Original Source: https://answers.mindstick.com/qa/93937/what-is-the-role-of-sortedlist-k-v-in-c-sharp-and-why-are-use-this-collection-in-c-sharp-explain-with-example

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
