33
1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
5
namespace LINQ_List
6
{
7
public class Program
8
{
9
public static void Main(string[] args)
10
{
11
List<int> ints = new List<int> { 3, 1, 2, 4 };
12
13
var result = ints.Where((x, i) =>
14
{
15
if (x == i)
16
{
17
Console.WriteLine(String.Format("{0}-{1}",x,i));
18
return true;
19
}
20
else
21
{
22
return false;
23
}
24
}).Select((x, i) => new { x, i });
25
26
foreach (var item in result)
27
{
28
Console.WriteLine(item);
29
};
30
}
31
}
32
}
33
Cached Result
2025/01/03 09:55:33
2025/01/03 09:55:33
2025/01/03 09:55:33