C#--List<> 分批次处理

  public  bool PushProductToBInit()
        {
             
            var pushlist =  _productToBService.GetAllProductToBSysNoList();

            //分批次数
            var oneCount = 50;
            var pushTimes = pushlist.Count % oneCount == 0 ? (pushlist.Count / oneCount) : (pushlist.Count / oneCount + 1);

            var pushonelist = new List<ProductToBUpdatePushModel>();
            for (var i = 0; i < pushTimes; i++)
            {
                if (i==(pushTimes-1))
                {
                    //最后一次 找到剩下数量
                    pushonelist = pushlist.GetRange(oneCount * i, pushlist.Count - (oneCount * i));
                }
                else
                {
                    pushonelist= pushlist.GetRange(oneCount * i, oneCount);
                }
                PushESB_ProductToB.GetInstance().Push_ProducUpdateToBTopic(pushonelist);
            }
           
            return true;
        }

你可能感兴趣的:(C#,c#)