score:8
Accepted answer
Try the following
dictionary
.SelectMany(pair => Enumerable.Repeat((double)pair.Key, pair.Value))
.OrderByDescending(x => x)
.ToList();
score:0
public static IEnumerable<T> Blowout<T>(T value, int length)
{
for (int i = 0; i < length; i++) yield return value;
}
dictionary
.SelectMany(pair => Blowout((double)pair.Key, pair.Value));
score:1
foreach (var pair in dict)
for (int i=0;i<pair.Value;i++)
list.Add((double)pair.Key);
score:5
dictionary
.SelectMany(kvp => Enumerable.Repeat(Decimal.ToDouble(kvp.Key), kvp.Value))
.ToList()
Source: stackoverflow.com
Related Query
- Blow dictionary out to a list
- c# Linq filter out records from a list within a dictionary
- List or Array of String Contain specific word in Html Source Code
- c# Linq or code to extract groups from a single list of source data
- Convert list to dictionary using linq and not worrying about duplicates
- LINQ - Convert List to Dictionary with Value as List
- Create a dictionary on a list with grouping
- Getting list of values out of list of objects
- Convert dictionary values to list using linq
- LINQ: Getting Keys for a given list of Values from Dictionary and vice versa
- Linq Query Dictionary where value in List
- C# LINQ - convert nested dictionary to a list
- Generating the Shortest Regex Dynamically from a source List of Strings
- Convert a list to a dictionary and sum up values using linq
- Select a section out of the middle of a list in C#
- List to Dictionary with incremental keys in one line LINQ statement
- Search dictionary values and return List of keys meeting conditions
- Function timed out for large list (LINQ query in C#)
- How do I combine the keys and values of a Dictionary into one List using LINQ?
- How can I pick random objects out of a list with C#?
- Await list of async predicates, but drop out on first false
- Create and initialize dictionary from list
- LINQ querying a Dictionary against a List
- Finding a value from within a List of Dictionary objects
- Coercing a LINQ result list of KeyValuePair into a Dictionary - Missing the Concept
- LINQ Source Code Available
- Use linq expression to filter a dictionary with a list of keys
- List of Dictionary to List<Type> using Linq
- Linq to Dictionary with key and a list
- Merging Dictionary containing a List in C#
More Query from same tag
- Filtering an ObservableCollection?
- how to convert system.linq.IQueryable<int?> to int?[]
- Group by using inner property in a list using Lambda expression
- int -> int list is not compatible with type int -> IEnumerable<'a>
- Add values to a list where data is missing
- Difference between two array of objects in C#
- Can this Linq query be typed as anything other than "var"?
- Reading an XML File With Linq
- Linq to SQL Join and Where
- Convert System collection list <anonymous> to generic list<myviewmodel> ASP.NET-MVC5
- How to get in LINQ one row for each key
- Linq query on Dictionary<int, double> type
- Join two tables to populate a viewModel with a nested collection
- select case in Datatable datarow in Linq
- Querying single table and merge result for same DateTime
- C# List Lambda with index, object and DoStuff() / to array
- Dynamic LINQ Unions possible?
- Add an index to a list to show a ranking from 1 to max items in the list
- Linq Where clause to generate List based on results of a different List
- Cannot implicitly convert type 'System.Linq.IQueryable<int>' to 'int?'
- Refactor LINQ ... multiplying property and child property from a list
- How to convert this foreach loop into Linq code?
- SQL to LINQ with many joins
- Error when combining Lambda expressions: "variable 'foo' of type 'Foo' referenced from the scope '', but it is not defined
- LinQ returning no datarow error
- sort only particular rows sql server
- ReSharper LINQ extension method formatting
- Choosing Database and ORM for a .NET project
- get only latest items for each id type
- Replace a list item value with another list item value based on multiple condition