Union - 2

Query
public void Linq49()
{
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 uniqueFirstChars = productFirstChars.Union(customerFirstChars);

Console.WriteLine("Unique first letters from Product names and Customer names:");
foreach (var ch in uniqueFirstChars)
{
Console.WriteLine(ch);
}
}
Lambda Expression
public void Linq49()
{
List products = GetProductList();
List customers = GetCustomerList();

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

var uniqueFirstChars = productFirstChars.Union(customerFirstChars);

Console.WriteLine("Unique first letters from Product names and Customer names:");
foreach (var ch in uniqueFirstChars)
{
Console.WriteLine(ch);
}
}
Output
Unique first letters from Product names and Customer names:
C
A
G
U
N
M
I
Q
K
T
P
S
R
B
J
Z
V
F
E
W
L
O
D
H
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +