计算总页数

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace Test
{
    class Program
    {
        /// <summary>
        /// 总页数
        /// </summary>
        /// <param name="pageSize">每页条数</param>
        /// <param name="totalCount">总条数</param>
        public static int TotalPages(int pageSize, int totalCount)
        {
            if (pageSize > 0 && totalCount > 0)
            {
                int totalPage = ((totalCount % pageSize) == 0) ? (totalCount / pageSize) : (totalCount / pageSize + 1);
                return totalPage;
            }

            return 0;
        }


        static void Main()
        {
            int pageSize = 20;
            int totalCount = 50;

            int page = TotalPages(pageSize, totalCount);
            Console.WriteLine("总页数:" + page.ToString()); //3


            Console.ReadLine();
        }

    }
}

 

posted @ 2016-08-04 12:59  茗::流  阅读(144)  评论(0)    收藏  举报
如有雷同,纯属参考。如有侵犯你的版权,请联系我。