Users Pricing

articles

home / developersection / articles / sorted list in csharp .net

Sorted list in CSharp .NET

Uttam Misra 8839 28 Jul 2010 Updated 04 Mar 2020

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

Sorted list in CSharp .NET

Sorted list in CSharp .NET



Uttam Misra

Information Technology

More than 18 years of working experience in IT sector. We are here to serve you best.


1 Comments


Markdown for AI

A clean, structured version of this page for AI assistants and LLMs.

Open .md