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 = newSortedList();
//creating sorted list.
privatevoid 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");
}
privatevoid 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
}
Rahul Roi
19-Oct-2019Thank you, Sir.
Realy its a good post for better practices.