linq_list

CSharp · Console

/Program.cs

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

namespace LINQ_List
{
    public class Program
    {
        public static void Main(string[] args)
        {
            List<int> ints = new List<int> { 3, 1, 2, 4 };

            var result = ints.Where((x, i) =>
            {
                if (x == i)
                {
                    Console.WriteLine(String.Format("{0}-{1}",x,i));
                    return true;
                }
                else
                {
                    return false;
                }
            }).Select((x, i) => new { x, i });

            foreach (var item in result)
            {
                Console.WriteLine(item);
            };
        }
    }
}
;