gpt4 book ai didi

c# - 将字典吹出到列表中

转载 作者:行者123 更新时间:2023-11-30 13:20:40 25 4
gpt4 key购买 nike

我有一本带有这个签名的字典:

Dictionary<decimal, int>

里面的元素是这样的:

90, 2
60, 3
30, 4
20, 1

我需要将其输出到具有此签名的列表中:

List<double>

里面的项目看起来像这样:

90
90
60
60
60
30
30
30
30
20

关于如何以优雅高效的方式做到这一点有什么想法吗?

最佳答案

尝试以下操作

dictionary
.SelectMany(pair => Enumerable.Repeat((double)pair.Key, pair.Value))
.OrderByDescending(x => x)
.ToList();

关于c# - 将字典吹出到列表中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5574142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com