Flattening

  • SelectMany()

// Some code
 var listOfListEmails = Customers.Select(x => x.Emails);

foreach (var listOfEmails in listOfListEmails)
{
    foreach (var email in listOfEmails)
    {
        Console.WriteLine(email);
    }
}
            
// Some code
var listOfEmails = Customers.SelectMany(x => x.Emails);

foreach (var email in listOfEmails)
{
    Console.WriteLine(email);
}

This will show the same result

Last updated