更換空從列表C#LINQ有意義的字符串
class Delivery
{
public string ProductCode
{
get;
set;
}
public DateTime? OrderedDate
{
get;
set;
}
public DateTime? DeliveryDate
{
get;
set;
}
public Delivery(string pcode, DateTime? orddate, DateTime? deldate)
{
ProductCode = pcode;
OrderedDate = orddate;
DeliveryDate = deldate;
}
}
List<Delivery> DeliveryList = new List<Delivery>();
DeliveryList.Add(new Delivery("P001",new DateTime(2009,01,27),null));
DeliveryList.Add(new Delivery("P007",new DateTime(2009,05,17),null));
DeliveryList.Add(new Delivery("P031", new DateTime(2008, 03, 15),
new DateTime(2008,04 ,22)));
DeliveryList.Add(new Delivery("P011",new DateTime(2009,01,27),
new DateTime(2009,02,12)));
DeliveryList.Add(new Delivery("P041",new DateTime(2009,01,27),null));
DeliveryList.Add(new Delivery("P051", new DateTime(2009, 01, 27),
new DateTime(2009, 02, 12)));
DeliveryList.Add(new Delivery("P501",new DateTime(2009,01,27),null));
DeliveryList.Add(new Delivery("P801",new DateTime(2009,01,27),null));
var query = DeliveryList.OrderBy(p => p.DeliveryDate);
對於報告的目的,在LINQ執行,什麼是 消息來代替空值(基於交貨日期)的方式「尚未交付「(DateTime是值類型)。
@Darin沒有ToArray()也代碼爲我工作,是否有必要包括ToArray()? – user215675 2009-12-03 07:35:32
ToArray非常重要。沒有它,結果將是每次嘗試使用它時重新執行的查詢。這可能會導致巨大的性能損失,具體取決於您如何使用它。 – 2009-12-03 07:42:28