Using LINQ, find the minimum value of an item property, in a collection, in a dictionary

c#, linq, linq-to-objects

Solution

Use `.SelectMany` to coalesce all the collections into one big sequence, then just use the standard `.Where` and `.Min` operators:

TheDictionary.Values
    .SelectMany(x => x)
    .Where(x => x.iMayBeNull == null)
    .Min(x => x.findMe);

Problem

``` public class Item { public double findMe{ get; set; } public int? iMayBeNull { get; set; } } public Dictionary<int, ICollection<Item>> TheDictionary{ get; set; } ... TheDictionary dict = new Dictionary<int, ICollection<Item>>(); ``` I'm trying to find the minimum value of "findMe" where "iMayBeNull" is null in all of "dict"'s collections. I can't seem to wrap my head around this one. Any guidance would be greatly appreciated.

Original source