2009-05-05 9 views
5

Voir le code ci-dessous, je ne sais pas pourquoi ma commande ne fonctionne pas, une idée?Comment commander un IEnumerable <T> de type anonyme?

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(); 

Répondre

10
var sortedList = ordersList.OrderBy(p => p.ProductName).ToList(); 

OrderBy() retourne une collection triée, il ne modifie pas la ordersList.

Si vous devez modifier la liste des commandes, utilisez Trier à la place.

+0

merci, fonctionne très bien !!! –

Questions connexes