本范例演示了C#中如果通过delegate给一个列表进行排序
// Create a simple example list List<string> TestList = new List<string>(); TestList.Add("Venezuela"); TestList.Add("Norway"); TestList.Add("Finland"); TestList.Add("Brazil"); TestList.Add("Germany"); TestList.Add("Australia"); TestList.Add("Fakeland"); // Sort the list by A-Z TestList.Sort(delegate(string A, string B) { return A.CompareTo(B); }); // Print out the test list foreach (string Country in TestList) Console.WriteLine(Country); /* Results: Australia Brazil Finland Germany Norway Venezuela */