ArrayUtil.cs 703 B

12345678910111213141516171819202122232425
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace Bsm.Core
  7. {
  8. internal static class ArrayUtil
  9. {
  10. public static T[][] SpliceByCount<T>(this T[] source, int count)
  11. {
  12. var pieces = new T[(int)Math.Ceiling(source.Length / (float)count)][];
  13. var idx = 0;
  14. for (var i = 0; i < source.Length; i += count)
  15. {
  16. var buffer = new T[source.Length - i < count ? source.Length - i : count];
  17. Array.Copy(source, i, buffer, 0, buffer.Length);
  18. pieces[idx++] = buffer;
  19. }
  20. return pieces;
  21. }
  22. }
  23. }