[英]How to order a IEnumerable<T> of anonymous type?
看下面的代碼,我不知道為什么我的訂單不起作用,有什么想法嗎?
var orderSample = new { ProductName = "", Qty = 0, UserFullName = "" };
var ordersList = (new[] { orderSample }).ToList();
//loop thru another collection and fill ordersList by adding an order at a time
ordersList.Add(new { ProductName = "Product1", Qty = 5, UserFullName = "Mr. Smith" });
//sort the orders by name - DOESN'T WORK
ordersList.OrderBy(p => p.ProductName);
gvReport3.DataSource = ordersList;
gvReport3.DataBind();
var sortedList = ordersList.OrderBy(p => p.ProductName).ToList();
OrderBy()返回一個已排序的集合,它不會修改ordersList。
如果需要修改ordersList,請改用Sort。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.