看到下面的代码,我不知道为什么我的订购不起作用,有什么想法吗?
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,请使用“排序”。
关于c# - 如何订购匿名类型的IEnumerable <T>?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/823430/