如何为customers变量的属性指定特定名称,例如:
伪码:
var customers = from c in Customers
where c.Orders.Count > 15
orderby c.Orders.Count ascending
select new {
c.ContactName as Name,
c.City,
c.Orders.Count as NumberOfOrders };
答案 0 :(得分:12)
像这样,使用object initializer syntax:
var customers = from c in Customers
where c.Orders.Count > 15
orderby c.Orders.Count ascending
select new
{
Name = c.ContactName,
c.City,
NumberOfOrders = c.Orders.Count
};