Select - Indexed: prints the value of the integer and whether it matches its index in the array : Index « LINQ « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass {
    public static void Main() {

        int[] numbers = { 5, 4, 1, 3, 9};

        var numsInPlace = numbers.Select((num, index) => new { Num = num, InPlace = (num == index) });

        foreach (var n in numsInPlace) {
            Console.WriteLine("{0}: {1}", n.Num, n.InPlace);
        }
    }
}








22.49.Index
22.49.1.Query by position
22.49.2.Use an indexed Where clause (where the length of the number's name is shorter than its value)
22.49.3.Select - Indexed: prints the value of the integer and whether it matches its index in the array
22.49.4.Use index when querying array with LINQ