C#list分页排序

/// <summary>
    /// 查询用户
    /// </summary>
    /// <param name="userName">用户名</param>
    /// <param name="role">角色</param>
    /// <param name="skipResults">开始行数</param>
    /// <param name="maxResults">最大行数</param>
    /// <param name="sortBy">排序</param>
    /// <returns>用户List</returns>
    public IList<MemberShipUser> GetUsers(string userName, string role, int skipResults, int maxResults, string sortBy)
    {
        IList<MemberShipUser> msuList = new List<MemberShipUser>();
        msuList=GetUsersCommon(userName, role);
        ///排序
        IList<MemberShipUser> list = new List<MemberShipUser>();
        switch (sortBy)
        {
            case "UserName":
                var list1 = from n in msuList orderby n.userName select n;
                list = list1.ToList();
                break;
            case "UserName DESC":
                var list2 = from n in msuList orderby n.userName descending select n;
                list = list2.ToList();
                break;
            case "role":
                var list3 = from n in msuList orderby n.role select n;
                list = list3.ToList();
                break;
            case "role DESC":
                var list4 = from n in msuList orderby n.role descending select n;
                list = list4.ToList();
                break;
        }
        ///分页
        if (list.Count != 0)
        {
            return list.Skip(skipResults).Take(maxResults).ToList();
        }
        else
            return msuList.Skip(skipResults).Take(maxResults).ToList();
    }

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