通过数组计数按降序排列列表

问题描述 投票:0回答:1

我正在尝试按照从每条记录中保留的投票量的降序对从数据库中获取的数据列表进行排序。这是我目前拥有的东西,但是无法正常工作。 注意:upvotes字段是模型类中的string []数组。

//Method to get all popular posts and display them in a list
    public async void GetPostInfo()
    {
        PostsMod = new ObservableCollection<IPosts>();
        var temp = await _postsProxy.GetAllPosts();

        if (temp != null)
        {
            if (temp.Count > 0)
            {
                var orderedList = temp.OrderByDescending(x => x.UpVoteId.Count()).ToList(); //Orders the records in descending order based on how many upvotes they contain, puts it into a new list

                foreach (var item in orderedList)
                {
                    PostsMod.Add(item);
                }
            }
            else
                PostsMod.Add(temp[0]);
        }
    }

[所有帖子都放入var temp,然后应该根据计数的upvotes数量以降序排列temp列表。请记住,upvote字段还是模型类中的string []数组。] >

它带有错误消息:System.ArgumentNullException:'值不能为null。参数名称:source'

编辑:抱歉,这是我的错误,我犯了愚蠢的错误,导致模型类中的字段不匹配。因此导致我的投票无效。

我正在尝试按照从每条记录中保留的投票量的降序对从数据库中获取的数据列表进行排序。这是我目前拥有的东西,但是无法正常工作。注意:upvotes字段是一个...

c#
1个回答
0
投票

[System.ArgumentNullException: 'Value cannot be null. Parameter name: source'来自传递给Linq扩展方法的空IEnumerable<T>,您代码中唯一的一个是<T>

© www.soinside.com 2019 - 2024. All rights reserved.