Метод IntersectBy
Метод IntersectBy класса Enumerable пересекает по ключу.
Синтаксис
IEnumerable<T> query = first.IntersectBy(second, x => key);
Пример
Давайте IntersectBy длины строк:
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
List<string> a = new List<string> {"a", "bb"};
List<string> b = new List<string> {"c", "dd"};
var res = a.IntersectBy(b, s => s.Length);
Console.WriteLine(string.Join(" ", res));
}
}
Результат выполнения кода:
"a"