以下程序来自于MSDN,修改了一下,通过VS2005运行
using System;
using System.Collections;
using System.Text;
namespace sortlist
{
class Program
{
static void Main(string[] args)
{
// Creates and initializes a new SortedList.
SortedList grade = new SortedList();
grade.Add("张三",85);
grade.Add("李四",87);
grade.Add("王五",77);
// Displays the properties and values of the SortedList.
Console.WriteLine("grade");
PrintKeysAndValues(grade);
Console.ReadLine();
}
public static void PrintKeysAndValues(SortedList myList)
{
Console.WriteLine("/t-KEY-/t-VALUE-");
for (int i = 0;
i < myList.Count;
i++)
{
Console.WriteLine("/t{0}:/t{1}", myList.GetKey(i), myList.GetByIndex(i));
}
Console.WriteLine();
}
}
}