分批

  /// <summary>
        /// 集合分批
        /// </summary>
        /// <typeparam name="T">数据类型</typeparam>
        /// <param name="lists">要分批的集合</param>
        /// <param name="Count">每批的数量</param>
        /// <returns>分批集合</returns>
        public static List<List<T>> SplitBatchs<T>(List<T> lists, int Count)
        {
            List<List<T>> batchs = new List<List<T>>();

            //集合数量
            long listCount = lists.Count;

            //分成的批次总数量
            long batchCount = (long)Math.Ceiling((double)listCount/(double)Count);

            if (Count>listCount)//一批
            {
                batchs.Add(lists);
            }
            else
            {
                for (int i = 0; i < batchCount; i++)
                {
                    batchs.Add(lists.Skip(i * Count).Take(Count).ToList());
                }
            }

            return batchs;
        }

  

原文地址:https://www.cnblogs.com/ItDotNet/p/6364304.html