I got this linq example from msdns 101 linq examples:
public void Linq12() {
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var numsInPlace = numbers.Select((num, index) => new {Num = num, InPlace = (num ==
index)});
Console.WriteLine("Number: In-place?");
foreach (var n in numsInPlace) {
Console.WriteLine("{0}: {1}", n.Num, n.InPlace);
}
}
Here are my questions:
What is the (num, index) part? Could these have been called anything such as a,b and can there be as many as I want?
How does the compiler determine what the type the anonymous type is going to be?
What is the => used for?
Must there always be at least one parameter. For example, in the following linq query is n a parameter or this select different from the other one (Select(num,index))
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 }; var numsPlusOne = from n in numbers select n + 1; }