本文实例讲述了C#实现泛型List分组输出元素的方法。分享给大家供大家参考,具体如下:
背景:在输出列表时,往往需要按照某一字段进行分组,比如在输出城市列表时,按照首字母进行分组,输出学生列表时,按照年级进行分组,然后再对分组的结果按照其他的字段进行排序。
如存在以下STU学生类,代码如下:
public class STU
{
public int ID { get; set; }
public string Name { get; set; }
public int Age { get; set; }
public string City { get; s