3
Answers

Fetch Min key in Linq var datatype?

T K

T K

9y
808
1
I have declared following dictionary-
 
 Dictionary<DateTime, List<Employee>> dictSource = new Dictionary<DateTime, List<Employee>>
{
{ DateTime.Now.AddDays(1), new List<Employee> { 1, "Programmers" }},
{ DateTime.Now.AddDays(3), new List<Employee> { 90, "Testers" }},
{ DateTime.Now.AddDays(2), new List<Employee> { 1, "Designers" }},
};
 
Then , I am extracting the records having minimum value of element at zero postion.
int MinValue = dictSource.Min(pair => pair.Value.ElementAt(0));
var filteredresults = dictSource.Where(pair => pair.Value.ElementAt(0) == MinValue);
 
Above code returns 2 items-
 1, "Programmers"
 1, "Designers"
 
Finally, I need to drill the 'filteredresults' collection so that it returns  the item having minimum date.
So, I should get the  '1, "Programmers"' as final value.
 
I have tried following but failing- 
filteredresults = filteredresults.ToDictionary(s => s.Key, s.Value);
 
Any help please?? 
Answers (3)