SortedList Class
Part of my 2008 study notes for exam 70-536 (.NET Framework 2.0).
Overview
- Key-value pair based collection.
- Contains DictionaryEntry objects.
- Accessible by index and key.
- Sorts items when they are added.
Good practice
- When possible, use a generic collection instead of the object-based SortedList.
Examples
Adding and Removing Elements
SortedList a = new SortedList();
a.Add("Key2", "Hello");
a.Add("Key1", "World");
a.Add("Key0", "Start");
Console.WriteLine(a["Key1"] + " " + a["Key2"]);
Console.WriteLine();
foreach (DictionaryEntry d in a) { Console.WriteLine(d.Value); }
Console.WriteLine();
foreach (var v in a.Values) { Console.WriteLine(v); }
Console.WriteLine();
a.Remove("Key1");
foreach (var k in a.Keys) { Console.WriteLine(a[k]); }
You May Also Like
ArrayList Class
Resizeable, unordered, index-based collection. Suffers from boxing/unboxing when working with value types. Implements IEnumerator, allowing foreach…
BinaryReader Class and BinaryWriter Class
Used to read and write binary data from streams. Call the correct Read methods when using a BinaryReader.
BitArray Class
Contains an array of true/false values. Resizable through the Length property. Supports bitwise operations.



