吹字典到列表

Jer*_*amp 3 c# linq dictionary

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

Dictionary<decimal, int>
Run Code Online (Sandbox Code Playgroud)

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

90, 2
60, 3
30, 4
20, 1
Run Code Online (Sandbox Code Playgroud)

我需要把它吹到一个有这个签名的列表:

List<double>
Run Code Online (Sandbox Code Playgroud)

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

90
90
60
60
60
30
30
30
30
20
Run Code Online (Sandbox Code Playgroud)

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

Jar*_*Par 8

请尝试以下方法

dictionary
  .SelectMany(pair => Enumerable.Repeat((double)pair.Key, pair.Value))
  .OrderByDescending(x => x)
  .ToList();
Run Code Online (Sandbox Code Playgroud)


spe*_*der 5

dictionary
    .SelectMany(kvp => Enumerable.Repeat(Decimal.ToDouble(kvp.Key), kvp.Value))
    .ToList()
Run Code Online (Sandbox Code Playgroud)