Mega Code Archive

 
Categories / C# Book / 04 LINQ
 

0478 Intersect - 2

public void Linq51() { List<Product> products = GetProductList(); List<Customer> customers = GetCustomerList(); var productFirstChars = from p in products select p.ProductName[0]; var customerFirstChars = from c in customers select c.CompanyName[0]; var commonFirstChars = productFirstChars.Intersect(customerFirstChars); Console.WriteLine("Common first letters from Product names and Customer names:"); foreach (var ch in commonFirstChars) { Console.WriteLine(ch); } } Result Common first letters from Product names and Customer names: C A G N M I Q K T P S R B V F E W L O