Advertisement
Guest User

Untitled

a guest
Oct 8th, 2020
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ThreadsUploadOrDownload
  8. {
  9.     class QueueZ<T> : Queue<T>
  10.     {
  11.         public IEnumerable<T> DequeueList()
  12.         {
  13.             List<T> list = new List<T>();
  14.             for (int i = 0; i < count; i++)
  15.             {
  16.                 if (!(this.Count > 0)) break;
  17.                 list.Add(base.Dequeue());
  18.             }
  19.             return list;
  20.         }
  21.         private IEnumerable<T> DequeueListAll()
  22.         {
  23.             return this;
  24.         }
  25.         int count;
  26.         public QueueZ(IEnumerable<T> enumerable,int count):base(enumerable)
  27.         {
  28.             this.count = count;
  29.         }
  30.     }
  31.     class SplitArray
  32.     {
  33.         public List<IEnumerable<T>> Start<T>(IEnumerable<T> list,int count)
  34.         {
  35.             List<IEnumerable<T>> result = new List<IEnumerable<T>>();
  36.             var query =  new QueueZ<T>(list,list.Count()/count);
  37.             for (int i = 0; i < count; i++)
  38.             {
  39.                 result.Add(query.DequeueList());
  40.             }
  41.             if (result.Count > 0) result.Add(query.DequeueList());
  42.             return result;
  43.         }
  44.     }
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement