今天对你来说可能很简单,但我现在正在围成一圈.考虑这种情况:
var tempDictionary = new Dictionary<string, int>();
tempDictionary.Add("user 1", 5);
tempDictionary.Add("user 2", 3);
tempDictionary.Add("user 3", 5);
Console.WriteLine(tempDictionary.Min(x => x.Key) + " => " tempDictionary.Min(x => x.Value);
Run Code Online (Sandbox Code Playgroud)
以上返回"user 1 => 3".
你会如何在字典中以最低值返回密钥?我之后的输出看起来像这样:"user2 => 3"
有任何想法吗?
list.Min()得到最小值为整数.我想获取List中具有特定属性X的最小值的对象.我该怎么做?
我面临排序列表的问题,我试图找到最便宜的价值.排序不是问题,它返回的值是问题和我想要满足的条件.
基本上我的结果集中可能有0个值,这是因为这些项目已被暂时搁置,因此它们没有保留值但引用仍然为它们到达.
我们的想法是按总价值对结果进行排序,然后选择列表中的第一项,理论上它是最便宜的.
void Main()
{
GetCheapest();
}
public void GetCheapest()
{
List<Car> numbers = new List<Car>
{
new Car() { Type="dearest", Total = 990 },
new Car() { Type="", Total = 570 },
new Car() { Type="", Total = 907 },
new Car() { Type="cheapest", Total = 0 },
new Car() { Type="", Total = 333 },
new Car() { Type="", Total = 435 },
new Car() { Type="", Total = 435 }
};
//order ascending
IEnumerable<Car> query = …Run Code Online (Sandbox Code Playgroud)