Monday, April 26, 2010

LINQ Samples (Projection Operators) : Select Transformation

Following example will obtain the odd string from there index position based on the value from a different array. If this is to be acheived by for loop; two for loops are required.


private void SimpleSelectTransformation()
{
int[] num = { 1, 3, 5, 7, 9};

string[] strTechn = new string[] { "C#", "asp.net", "vb.net", "j#", "f#", "Cobol.net", "LINQ", "WCF", "WPF", "Silverlight" };
var trans1 = num.Select(a => strTechn[a]);

foreach (string s in trans1)
{
Console.WriteLine(s);
}
}


OUTPUT:

asp.net
j#
Cobol.net
WCF
Silverlight