c# - 从 System.Collections.Generic.List c# 中选择 x 个元素

标签 c# list

我需要的是一种从列表中选择最后 100 个元素的方法,作为列表

    public List<Model.PIP> GetPIPList()
    {
        if (Repository.PIPRepository.PIPList == null)
            Repository.PIPRepository.Load();
        return Repository.PIPRepository.PIPList.Take(100);

    }

我得到这样的错误

“System.Collections.Generic.IEnumerable”到“System.Collections.Generic.List”。存在显式转换(是否缺少强制转换?)

最佳答案

somelist.Reverse().Take(100).Reverse().ToList();

这比订购便宜得多 :) 还保留了原始订购。

关于c# - 从 System.Collections.Generic.List c# 中选择 x 个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8005103/

相关文章:

c# - .NET 中的开源 EDIFACT BAPLIE 解析器?

c# - 流畅的NHibernate批量数据插入

c# - 哪个本地 ip 连接到远程 ip?

c# - 如何在安装应用程序的 hkey_classes_root 键上添加值

java - java中如何获取ArrayList中的元素

c# - 我可以使用什么算法在 C# 中对这个分支列表进行排序?

c# - 复制然后删除 Azure 文件时,删除是否总是在复制完成后开始?

python - 如何在列表中的某些位置\n

python - 有没有办法缩短 python 中以列表删除或附加项目结尾的多个嵌套 for 和 if 循环?

list - Scala List.contains(x) 返回false,但exists(_.== x) 返回true