PART I
C h a p t e r 1 9 :
L I N Q
571
PART IPART I
// Create a query that joins Item with InStockStatus to
// produce a list of item names and availability.
// Now, an anonymous type is used.
var inStockList = from item in items
join entry in statusList
on item.ItemNumber equals entry.ItemNumber
select new { Name = item.Name,
InStock = entry.InStock };
Console.WriteLine("Item\tAvailable\n");
// Execute the query and display the results.
foreach(var t in inStockList)
Console.WriteLine("{0}\t{1}", t.Name, t.InStock);
}
}
Pay special attention to the
select
clause:
select new { Name = item.Name,
InStock = entry.InStock };
It returns an object of an anonymous type that has two read-only properties,
Do'stlaringiz bilan baham: |