문제

I am new to LINQ.

I have a SortedDictionary

SortedDictionary<int, int> book = new SortedDictionary<int, int>();

and the pair are

(5,10),(7,20),(8,30),(9,15),(10,60)

Is there any LINQ statement that can allow me to selected the lowest key whose value is more than 25? For this example, it is the key is 8

도움이 되었습니까?

해결책

As it's a sorted dictionary (and therefore the first key matching the criteria is always the lowest key matching the criteria), you can just do:

var result = book.First(o => o.Value > 25).Key;

다른 팁

book.Where(i => i.Item > 25).Min(i => i.Key)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top