Resources For IT Professionals

# PIRATED 20130914 1650

The community rules state:
• "Someone else has relevant content and you want to help them share it with the world. It's a nice thought, but do not copy other people's content to the Wiki, even if the owner said it was OK."

Assuming we have multiple sequences as follows containing different set of elements :

`var bldgNum = new string[] {"A5", "A2", "A1" };var flatNum = new int[] {104, 109, 25, 200 };var streetNm = new string[] {"Baker Street", "Cross Street", "Hu Street" };var city = new string[] { "CO", "WA", "AU", "CA" };`

To merge the elements of all these sequences, use the Zip operator that is new in .NET Framework 4.0

“The method merges each element of the first sequence with an element that has the same index in the second sequence. If the sequences do not have the same number of elements, the method merges sequences until it reaches the end of one of them”

`static void CombineSeq(){var bldgNum = new string[] {"A5", "A2", "A1" };var flatNum = new int[] {104, 109, 25, 200 };var streetNm = new string[] {"Baker Street", "Cross Street", "Hu Street" };var city = new string[] { "CO", "WA", "AU", "CA" };var address = bldgNum    .Zip(flatNum, (bl, fl) => bl + ", " + fl.ToString())    .Zip(streetNm, (fl, st) => fl + " , " + st)    .Zip(city, (st, ct) => st + ", " + ct);foreach (var addr in address)    Console.WriteLine(addr);}`

OUTPUT

# Source

This topic was copied from this blog at DevCurry, by Suprotim Agarwal.

Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
• Carsten Siemens edited Revision 5. Comment: Pirated Content - see my comment

• XAML guy edited Revision 4. Comment: tweak

• XAML guy edited Revision 3. Comment: added source, do you have permission for this?

• Ed Price - MSFT edited Revision 1. Comment: Title casing. Adding tags.

Page 1 of 1 (4 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
• Ed Price - MSFT edited Revision 1. Comment: Title casing. Adding tags.

• XAML guy edited Revision 3. Comment: added source, do you have permission for this?

• XAML guy edited Revision 4. Comment: tweak

• Carsten Siemens edited Revision 5. Comment: Pirated Content - see my comment

• NOTE: This article was reported as Pirated/Plagiarized Content (content you didn't write) and will be removed. Please do not steal content from others. If you feel we are mistaken, please leave a comment or email tnwiki at Microsoft with a link to this article and with clear and detailed reasons why you own the content or have explicit permission from the author.

Content was taken from: "Combine Multiple Sequences in LINQ using the Zip Operator - .NET 4.0"