本文介绍了物业C#的收集与另一个属性的最小值选择值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我们可以说我有一个类型的车
有两个属性速度
和颜色
公共类车
{
公众诠释速度{获得;组;}
公共串色{获得;组;}
}
使用LINQ我可能发现的最小速度
INT minSpeed = collection.Min(EM => em.Speed);
将让minSpeed包含在集合中的最小速度的赛车速度值。
不过,我该怎么做类似让汽车的颜色的东西吗?
是这样的:
串色= collection.Min(EM => em.Speed)。选择(X => x.Color);
解决方案
使用的。
汽车slowestCar = collection.MinBy(EM => em.Speed);
串色= slowestCar.Color;
So let's say I have a type Car
with two properties Speed
and Color
public class Car
{
public int Speed {get; set;}
public string Color {get; set;}
}
Using LINQ I may find the minimum speed
int minSpeed = collection.Min(em => em.Speed);
so minSpeed will contain the value of speed of the car with the minimum speed in collection.
But how can I do something similar to get the color of the car?
Something like:
string color = collection.Min(em => em.Speed).Select(x => x.Color);
解决方案
Use MinBy.
Car slowestCar = collection.MinBy(em => em.Speed);
string color = slowestCar.Color;
这篇关于物业C#的收集与另一个属性的最小值选择值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!