C# 数组拆分

拆分C#


  public List> SplitList(List list, int size)
        {
            List> result = new List>();
            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;
        }




原始数组:

C# 数组拆分_第1张图片


拆分之后:

C# 数组拆分_第2张图片



你可能感兴趣的:(C#,数组拆分,C#)