将List拆分为多个List的扩展方法

/// <summary>
/// List帮助类
/// </summary>
public static class ListHelper
{
/// <summary>
/// 按指定数量对List分组
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="list"></param>
/// <param name="groupNum"></param>
/// <returns></returns>
public static List<List<T>> GetListGroup<T>(this List<T> list, int groupNum)
{
List<List<T>> listGroup = new List<List<T>>();
for (int i = 0; i < list.Count(); i += groupNum)
{
listGroup.Add(list.Skip(i).Take(groupNum).ToList());
}
return listGroup;
}
}

 

posted @ 2020-09-14 20:12  随便取个名字算了  阅读(4054)  评论(0编辑  收藏  举报