Concat operator example in C# LINQ

var Query12 = CustomerList.Where(c = > c.Country == “USA”)
                    .Concat(CustomerList.Where(c = > c.Country == “Canada”)
                    .Concat(CustomerList.Where(c = > c.Country == “Mexico”)));
 
Query12 = (from c in CustomerList
                 where c.Country == “USA”
                 select c)
                .Concat((from c in CustomerList
                 where c.Country == “Canada”
                 select c)
                 .Concat((from c in CustomerList
                 where c.Country == “Mexico”
                 select c)));
 
foreach (var c in Query12)
           sbResult.Append(String.Format(“CustID = {0}, Name = {1}, Country = {2}\r\n”,
           c.CustomerID, c.CompanyName, c.Country));

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.