C# Linq: Zip method

string[] brands = new string[] { "BMW", "Mercedes", "Audi" };
string[] websites = new string[] { "www.bmw.com", "www.mercedes.com", "www.audi.com" };

var output = brands.Zip(websites, (b, w) => string.Format("{0} can be found at {1}", b, w));

foreach (var line in output)

This gives you:

BMW can be found at www.bmw.com 
Mercedes can be found at www.mercedes.com 
Audi can be found at www.audi.com

More information at: http://msdn.microsoft.com/en-us/library/dd267698.aspx


SelectMany in LINQ (C#)

This is an example of using SelectMany in Linq (Method notation):

string[] allItems = { "item1", "item2", "item3" };
string[] databaseItems = { "item2" };

var data = allItems
.SelectMany(item => databaseItems , (item, dbItem) => new { item, dbItem })
.Where(x => !x.item.Equals(x.dbItem, StringComparison.InvariantCultureIgnoreCase))
.Select(x => x.item);

foreach (var v in data)

// LinqPad specific code:

The result is item1 and item3.
This example takes all the items from allItems that don’t exist in databaseItems.