Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In the below example, how to return row having minimum value at element(0) of dictionary?

C#
Dictionary<int, List<Employee>> dictSource = new Dictionary<int, List<Employee>>
{
{ 1, new List<Employee> { 5, "Programmers" }},
{ 1, new List<Employee> { 12, "Testers" }},
{ 2, new List<Employee> { 2, "Designers" }},
};


I want to return the following data from above dictionary-

2, "Designers"


I have written below:

C#
string sminValue= dictSource.Min(pair => pair.Value.ElementAt(0)) 


But it returns the incorrect results, Can anyone guide, what I am doing wrong?
Posted
Comments
Kornfeld Eliyahu Peter 22-Jun-15 5:40am    
How Employee defined?

Try this-
C#
string sminValue = dictSource.MinBy(pair => pair.Value).Value;

or
C#
var minRow = dictSource.MinBy(pair => pair.Value);


N:B: Haven't executed these but something like this should work :)
 
Share this answer
 
Suvendu,

The ".MinBy" function is not supported by my version of C# (framework 4.0)
Any other workaround?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900