Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

split array into pieces of x length c#

static List<List<int>> SplitArray(List<int> originalArray, int chunkSize)
{
  var list = new List<List<int>>();
  var ls = new int[chunkSize];
  for (int i = 0; i <= originalArray.Count-chunkSize; i++)
  {
    originalArray.CopyTo(i, ls,0, chunkSize);
    list.Add(ls.ToList());
  }
  return list;
}
 
PREVIOUS NEXT
Tagged: #split #array #pieces #length
ADD COMMENT
Topic
Name
9+9 =