页码数pageSize

 

//先设定好一页有多大的Size
int pagesize = 100;
//(总的Count数)÷pagesize==>之后的结果再向上取整Math.Ceiling
Math.Ceiling(0.4) //1
Math.Ceiling(0.5) //1
Math.Ceiling(0.6) //1
//这样就知道有多少"页"
int pagenum = Convert.ToInt32(Math.Ceiling((double)skus.Count/ pagesize));
//然后就可以每一页每一页的进行操作了,操作完一页就换下一页
for (int i = 0; i < pagenum; i++)
    {
      var tempsku = skus.Skip(i * pagesize).Take(pagesize);
      XDocument obj = new XDocument(new XDeclaration("1.0", "utf-8", "yes"));
      //构造根节点
      obj.Add(new XElement("request",
              new XElement("criteriaList", tempsku.Select(l => 
                            new XElement("criteria",
                            new XElement("ff", ff),
                            new XElement("aa", aa),
                            new XElement("bb", l.sku),
                            new XElement("cc", ""))))));
      XmlDocument doc = new XmlDocument();
      doc.LoadXml(obj.ToString());
      //拼接url
      string url = GenerateUrl("xxx", appkey, whse, apiurl, secret, doc, timestamp);
      var result = this.Post(url, doc); 
   }

C#取整函数Math.Round、Math.Ceiling和Math.Floor

1.Math.Round(圆形的,球形的):四舍六入五取偶

Math.Round(0.0) //0
Math.Round(0.4) //0
Math.Round(0.5) //0
Math.Round(0.6) //1
Math.Round(0.7) //1

说明:对于1.5,因要返回偶数,所以结果为2。

2.Math.Ceiling(天花板,向上取整):只要有小数都加1

Math.Ceiling(0.0) //0
Math.Ceiling(0.4) //1
Math.Ceiling(0.5) //1
Math.Ceiling(0.6) //1
Math.Ceiling(0.7) //1

说明:例如在分页算法中计算分页数很有用。

3.Math.Floor(地板,向下取整):总是舍去小数

Math.Floor(0.0) //0
Math.Floor(0.4) //0
Math.Floor(0.5) //0
Math.Floor(0.6) //0
Math.Floor(0.7) //0
posted @ 2021-03-03 10:28  ProZkb  阅读(413)  评论(0编辑  收藏  举报