如何在元素(0)返回最小值的字典行? [英] How to return dictionary row with minimum value at element(0)?

查看:62
本文介绍了如何在元素(0)返回最小值的字典行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的例子中,如何在字典的元素(0)处返回具有最小值的行?



In the below example, how to return row having minimum value at element(0) of dictionary?

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" }},
};





我想从上面的字典中返回以下数据 -



2,设计师





我写的如下:





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, Can anyone guide, what I am doing wrong?

推荐答案

试试这个 -

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






or

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





N:B:没有执行过这些但这样的事情应该有效:)



N:B: Haven't executed these but something like this should work :)


Suvendu,



我的C#版本(框架4.0)不支持.MinBy功能

还有其他解决方法吗?
Suvendu,

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


这篇关于如何在元素(0)返回最小值的字典行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆