Another LINQ 101 question

M

Mike P

In the SelectManyIndexed example (see below), what syntax do you need to
actually write the results of the query to the screen?

var customerOrders =
customers.SelectMany(
(cust, custIndex) =>
cust.Orders.Select(o => "Customer #" + (custIndex + 1) +
" has an order with OrderID " +
o.OrderID));
 
P

Pavel Minaev

In the SelectManyIndexed example (see below), what syntax do you need to
actually write the results of the query to the screen?

var customerOrders =
            customers.SelectMany(
                (cust, custIndex) =>
                cust.Orders.Select(o => "Customer #" + (custIndex + 1) +
                                        " has an order with OrderID " +
o.OrderID));

Just plain old foreach?

foreach (var o in customerOrders) Console.WriteLine(o);

You can of course remove customerOrders entirely, and move the entire
LINQ expression inside foreach(), though in this case it would
probably hamper readability.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

LINQ 101 question 1
LINQ Newbie 3
Var vs Object type 4
help creating a customer list for a linq query 2
LINQ 101 error 2
How to benchmark LINQ query? 1
Simple LINQ question 3
Question about LinQ (LinQ to Sql) 4

Top