我有以下课程:
class Seller
{
private string sellerName;
private decimal price;
}
~propreties for SellerName and Price goes here~
Run Code Online (Sandbox Code Playgroud)
我还有一份卖家名单:
list<Seller> s = new list<Seller>();
Run Code Online (Sandbox Code Playgroud)
如何price从所有卖家中获得最大价值?
非常感谢你.
您可以像这样使用linq:
var max = s.Select(o => o.Price).Max();
//or this
var max = s.Max(o => o.Price);
Run Code Online (Sandbox Code Playgroud)
为了实现这一点,price需要这样才能实现public.
您也可以以最高价格获得卖家,如下所示:
var maxPriceSeller = s.OrderByDescending(o => o.Price).First();
Run Code Online (Sandbox Code Playgroud)
(Price作为你所在price领域的财产)