public class Program { public static void Main() { // 创建一个放入ilookup数据结构的School清单。 List<School> schools = new List<School> { new School { University = "西南交通大学",Address="成都"}, new School { University = "北京交通大学" ,Address="北京"}, new School { University = "西南政法大学" ,Address="重庆"}, new School { University = "北京航空航天大学" ,Address="北京"}, new School { University = "清华大学",Address="北京"} }; // 创建一个查询来组织packages集合。使用大学的第一个字符作为关键值。 //ILookup 对象中选择大学(University)附加大学地址(Address)作为每一个元素的值。 ILookup<char, string> schoolLookup = schools.ToLookup( p => Convert.ToChar(p.University.Substring(0, 1)), p => p.University + " " +p.Address ); // 在ilookup遍历和输出内容的每个值。 foreach (var packageGroup in schoolLookup) { // 打印的关键值。 Console.WriteLine(packageGroup.Key); // 遍历集合中的每个值。 foreach (string str in packageGroup) Console.WriteLine(" {0}", str); } } } class School { public string University { get; set; } public string Address { get; set; } }