T K

T K

  • NA
  • 31
  • 6.3k

How to return dictionary with minimum value at element(0)

Jun 22 2015 5:46 AM
In the below example, how to return row have minimum value at element(0) of dictionary?
 
 Dictionary<int, List<string>> dictSource2 = new Dictionary<int, List<string>>
{
{ 1, new List<string> { "5", "Programmers" }},
{ 2, new List<string> { "12", "Testers" }},
{ 3, new List<string> { "2", "Designers" }},
};
 
I want to return the following data from above dictionary-
"2", "Designers"
I have written below:
 
string sminValue= dictSource.Min(pair => pair.Value.ElementAt(0))
 
But it returns the incorrect results.Note, my solution woks fine when value at ElementAt(0) has zero records. Can anyone guide here?

Answers (4)