Get Min and Max values in dictionary
hello,
i have following dictionary:
dictionary<string, int32> items = new dictionary<string, int32>() { { "a", 1 }, { "b", 2 }, { "c", 3 }, { "d", 4 }, { "e", 5 }, { "f", 6 }, };
given list of string, let's say:
list<string> list = new list<string> { "b", "d", "e" };
i need minimum , maximum values list items. list get:
minimum = 2 (value of b in dictionary)
maximum = 5 (value of e in dictionary)
what best way this? trying linq max, min not sure how intersection between list , dictionary.
thank you,
miguel
one solution this:
var min = list.select(k => items[k]).min(); var max = list.select(k => items[k]).max();
Visual Studio Languages , .NET Framework > Visual C#
Comments
Post a Comment