这是条不归路

呜呜呜~

导航

c# 拆分list

        /// <summary>
        /// 拆分list
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list">原始list</param>
        /// <param name="blockSize">拆分长度</param>
        /// <returns></returns>
        public List<List<T>> GetBlockList<T>(List<T> list, int blockSize = 500)
        {
            List<List<T>> result = new List<List<T>>();
            var temp = new List<T>();
            for (int i = 0; i < list.Count; i++)
            {
                temp.Add(list[i]);
                if ((i + 1) % blockSize == 0 && i > 0)
                {
                    result.Add(temp);
                    temp = new List<T>();
                }
                if (i == list.Count - 1)
                {
                    result.Add(temp);
                }
            }
            return result;
        }

 

posted on 2023-05-24 17:27  En'  阅读(112)  评论(0编辑  收藏  举报