在C#中,可以使用LINQ的Intersect方法來處理嵌套集合的交集問題。下面是一個(gè)示例代碼:
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static void Main()
{
List<List<int>> nestedList1 = new List<List<int>>
{
new List<int> {1, 2, 3},
new List<int> {2, 3, 4},
new List<int> {3, 4, 5}
};
List<List<int>> nestedList2 = new List<List<int>>
{
new List<int> {2, 3, 4},
new List<int> {3, 4, 5},
new List<int> {4, 5, 6}
};
var intersection = nestedList1.SelectMany(x => x)
.Intersect(nestedList2.SelectMany(y => y))
.ToList();
foreach (var item in intersection)
{
Console.WriteLine(item);
}
}
}
在這個(gè)示例中,我們有兩個(gè)嵌套的List<List