You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

32 lines
756 B

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ButcherFactory.BO.Utils
{
public static class ButcherFactoryUtil
{
public static List<List<T>> SplitList<T>(List<T> list, int size)
where T : new()
{
List<List<T>> result = new List<List<T>>();
for (int i = 0; i < list.Count() / size; i++)
{
T[] clist = new T[size];
list.CopyTo(i * size, clist, 0, size);
result.Add(clist.ToList());
}
int r = list.Count() % size;
if (r != 0)
{
T[] cclist = new T[r];
list.CopyTo(list.Count() - r, cclist, 0, r);
result.Add(cclist.ToList());
}
return result;
}
}
}