Combine

Query
public void Linq98() {            
int[] vectorA = { 0, 2, 4, 5, 6 };
int[] vectorB = { 1, 3, 5, 7, 8 };

int dotProduct = vectorA.Combine(vectorB, (a, b) => a * b).Sum();

Console.WriteLine("Dot product: {0}", dotProduct);
}
Lambda Expression
public void DataSetLinq98()
{
var numbersA = testDS.Tables["NumbersA"].AsEnumerable();
var numbersB = testDS.Tables["NumbersB"].AsEnumerable();

int dotProduct = numbersA.Combine(numbersB, (a, b) => a.Field("number") * b.Field("number")).Sum();
Console.WriteLine("Dot product: {0}", dotProduct);
}
Output
Dot product: 109
Follow Us
https://www.facebook.com/Rookie-Nerd-638990322793530 https://twitter.com/RookieNerdTutor https://plus.google.com/b/117136517396468545840 #
Contents +