更新时间:2023-02-17 20:21:37
可以做到这一点只需使用的设置逻辑。 C#在 HashSet的:
You can achieve this simply using Set logic. C# has a nice implementation in the form of HashSet:
var set = new HashSet<OtherObject>(myObjects.SelectMany(mo => mo.ObjectList));
或者,如果你愿意延迟执行,你可以使用LINQ的Distinct 方式:
var distinct = myObjects.SelectMany(mo => mo.ObjectList).Distinct();