I need to get a Kvp from a list of List<KeyValuePair<Int, Int>> depending on the minimum value.
I have tried this:
KeyValuePair<Int, Int> kvp= listOfKvps.Min(e=> e.Key);
but this return only the value, not the whole KeyValuePair which I need.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There is no inbuilt
MinBymethod, so you could either write aMinByextension method, or just.OrderBy(x => x.Key).First(). AMinBywould beO(n)so would be more efficient – but more code to write ;pFor example, you could use:
with: