Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Using LINQ Concat to Loop Over Two Arrays with Same Type of Elements

Learn to use the Concat operator in LINQ to loop thru collections in one go.


advertisement

Often, there are multiple collections with the same kind of elements, that we would have to loop on. Instead of writing two for loops over the collections, we can use the Concat operator in Linq to loop thru the collections in one go.

string[] emeaClients = { "John Frank", "Carine Bothe" };
string[] northAmericanClients = { "John Ferry", "Mickey Kate" };

foreach (var client in emeaClients.Concat(northAmericanClients))
{
    Console.WriteLine(client);
} 

 



Visit the DevX Tip Bank

 



   
Srinath M. S. says: "I would love to leave a footprint in this flat world."
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date