C#/공부기록
[C#] Linq / index, value
프디
2023. 1. 14. 23:35
ㆍindex, value 사용
<예제>
using System;
using System.Linq;
class ex
{
static void Main(string[] args)
{
int[] a = new int[] { 1, 2, 4 };
string[] b = new string[] { "a", "b", "c", "d" };
var query =
from i in a.Select((value, index) => new { index, value })
from s in b.Select((value, index) => new { index, value })
where i.value == (s.index + 1)
select new
{
i = i.value,
s = s.value
};
foreach (var item in query)
Console.WriteLine($"{item}");
}
}
