我有一个价格矩阵列表,我存储的宽度,长度和价格的项目。我想从输入宽度和长度中找到最大的宽度和高度。例如,比方说,如何使用LINQ从列表<Price>获取最接近的数字?
Public Class ItemPrice
{
public int id{ get; set; }
public string item{ get; set; }
public int width{ get; set; }
public int height{ get; set; }
public decimal price{ get; set; }
}
List<ItemPrice> itemorder = new List<ItemPrice>();
itemorder.Add(new ItemPrice(1,"A",24,12,$12.24));
itemorder.Add(new ItemPrice(2,"A",24,14,$16.24));
itemorder.Add(new ItemPrice(3,"A",36,12,,$18.24));
itemorder.Add(new ItemPrice(4,"A",36,14,$21.24));
这意味着它看起来像
24 36
--------------------
12 | $12.24 $18.24
14 | $16.24 $21.24
我怎样才能找到ITEMPRICE ID 4作为宽度= 30高度= 13的结果?以及如果宽度= 40和高度= 16如何返回空值?
请确切地说明H en W.的顺序。发布该构造函数的第一行。 –
@HenkHolterman:我只想知道背后的逻辑,所以这就是为什么我没有在我的问题中写入构造函数。 –
W = 10,H = 26应该返回什么?而对于W = 10,H = 10? –