Distinct - 2

Query
public void Linq47()
{
List products = GetProductList();

var categoryNames = (
from p in products
select p.Category)
.Distinct();

Console.WriteLine("Category names:");
foreach (var n in categoryNames)
{
Console.WriteLine(n);
}
}
Lambda Expression
public void Linq47()
{
List products = GetProductList();

var categoryNames = (products.Select(prod => prod.Category)).Distinct();

Console.WriteLine("Category names:");
foreach (var n in categoryNames)
{
Console.WriteLine(n);
}
}
Output
Category names:
Beverages
Condiments
Produce
Meat/Poultry
Seafood
Dairy Products
Confections
Grains/Cereals
Related Tutorial
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 # # # # #