Except - 2

Query
public void Linq53()
{
List products = GetProductList();
List customers = GetCustomerList();

var productFirstChars =
from p in products
select p.ProductName[0];
var customerFirstChars =
from c in customers
select c.CompanyName[0];

var productOnlyFirstChars = productFirstChars.Except(customerFirstChars);

Console.WriteLine("First letters from Product names, but not from Customer names:");
foreach (var ch in productOnlyFirstChars)
{
Console.WriteLine(ch);
}
}
Lambda Expression
public void Linq53()
{
List products = GetProductList();
List customers = GetCustomerList();

var productFirstChars = products.Select(prod => prod.ProductName[0]);
var customerFirstChars = customers.Select(cust => cust.CompanyName[0]);

var productOnlyFirstChars = productFirstChars.Except(customerFirstChars);

Console.WriteLine("First letters from Product names, but not from Customer names:");
foreach (var ch in productOnlyFirstChars)
{
Console.WriteLine(ch);
}
}
Output
First letters from Product names, but not from Customer names:
U
J
Z
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 # # # # #