Monday, April 26, 2010

LINQ Samples (Projection Operators) : Select Indexed

In this example we explore the index for a given enumeration. In the statement
var str = strTech.Select( (a, b) => new { condition = a.Length > b , strTech = a });


a is the object strTech , b in the index or position of enumeration, new {} is the anonymous type.


private void SelectIndexed()
{
int[] num = { 1,2,3,4,5,6,7,8,9};
string[] strTech = new string[] { "C#", "asp.net", "vb.net", "j#", "f#", "Cobol.net", "LINQ", "WCF", "WPF", "Silverlight" };

var str = strTech.Select( (a, b) => new { condition = a.Length > b , strTech = a });

foreach (var s in str)
{
Console.WriteLine("{0}\t{1}", s.strTech, s.condition);
}
}


OUTPUT

C# True
asp.net True
vb.net True
j# False
f# False
Cobol.net True
LINQ False
WCF False
WPF False
Silverlight True