2009-05-05 7 views
5

Vea el siguiente código, no sé por qué mi orden no funciona, ¿alguna idea?¿Cómo pedir un IEnumerable <T> de tipo anónimo?

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

Respuesta

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

OrderBy() devuelve una colección ordenada, que no modifica la ordersList.

Si necesita modificar la lista de pedidos, utilice Ordenar en su lugar.

+0

gracias, funciona genial !!! –

Cuestiones relacionadas