Mid Collections

How do you add, remove, or search for elements in a SortedList<TKey, TValue>?

Add:

sortedList.Add(4, "Four");

Remove:

sortedList.Remove(2); // Remove element with key 2

Search (by key):

bool exists = sortedList.ContainsKey(3);

string value = sortedList[3]; // Access value by key

More from C# Programming Tutorial

All questions for this course