如何将带有对象的字典转换为该类型的列表

本文关键字:转换 类型 列表 字典 对象 | 更新日期: 2023-09-27 18:21:00

如何将以下字典转换为通道对象列表?我尝试了ToList()方法,但似乎无法使其工作。

List<Items> items = new List<Items>();
Dictionary<int, Items> foundItems = 
    statsCont.OrderByDescending(x => x.Value.NumberOfItems)
        .Take(10)
        as Dictionary<int, Items>;

如何将带有对象的字典转换为该类型的列表

您尝试过吗:

foundItems.Values.ToList();

怎么样:

List<Items> items = statsCont.OrderByDescending(x => x.Value.NumberOfItems)
    .Take(10)
    .Select(x => x.Value)
    .ToList();