---
title: "Sorted list in CSharp .NET"  
description: "/* Style Definitions */   table.MsoNormalTable  	{mso-style-name:\"Table Normal\";  	mso-tstyle-rowband-size:0;  	mso-tstyle-colband-size:0;  	mso-st"  
author: "Uttam Misra"  
published: 2010-07-28  
updated: 2020-03-04  
canonical: https://www.mindstick.com/articles/90/sorted-list-in-csharp-dot-net  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Sorted list in CSharp .NET

SortedList represents a collection of key-and-value pairs that are sorted by the keys and are accessible by key and by index.

```
SortedList sl = new SortedList();//creating sorted list.private void btnAdd_Click(object sender, EventArgs e){if (txtValue.Text != "" && txtKey.Text != "")      {        sl.Add(txtKey.Text, txtValue.Text);//adding key and value to sorted list.            txtKey.Text = "";            txtValue.Text = "";      }      else            MessageBox.Show("Text Box Empty");} private void btnDisplay_Click(object sender, EventArgs e){ ICollection ic = sl.Keys;//assigning sortedlist key to ICollection variable.foreach (string str in ic)MessageBox.Show(str + ": " + sl[str]);//executing loop for each key avaliable      }
```

##### Screen Shot

##### ![Sorted list in CSharp .NET](https://www.mindstick.com/mindstickarticle/314386f2-11ec-4d39-a5b2-3d223dc4f51a/images/7ab302ec-106e-4f6f-a300-6b0c502bf439.png)\

![Sorted list in CSharp .NET](https://www.mindstick.com/mindstickarticle/314386f2-11ec-4d39-a5b2-3d223dc4f51a/images/7bd26e84-04da-49ba-81f5-18cb6eff3360.png)

![Sorted list in CSharp .NET](https://www.mindstick.com/mindstickarticle/314386f2-11ec-4d39-a5b2-3d223dc4f51a/images/de972149-8da3-44ab-8153-6b7767d77698.png)

\

---

Original Source: https://www.mindstick.com/articles/90/sorted-list-in-csharp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
