Linq - Group join sample

Saratvaddilli
Posted by Saratvaddilli under LINQ category on | Points: 40 | Views : 1456
public void LinqSample()
{
string[] categories = new string[]{
"Beverages",
"Condiments",
"Vegetables",
"Dairy Products",
"Seafood" };

List<Product> products = GetProductList();

var q =
from c in categories
join p in products on c equals p.Category into ps
select new { Category = c, Products = ps };

foreach (var v in q)
{
Console.WriteLine(v.Category + ":");
foreach (var p in v.Products)
{
Console.WriteLine(" " + p.ProductName);
}
}
}

Comments or Responses

Login to post response