c# - 您能否使用 linq 查看两个 IEnumerables 数据是否包含任何公共(public)条目?

标签 c# .net linq ienumerable

IEnumerable<fishbiscuits> a = GetFishBiscuits(0);
IEnumerable<fishbiscuits> b = GetFishBiscuits(1);

if ([any of the results in either list match])
{
 // Do something ie
 Console.WriteLine("I see both a and b love at least one of the same type of fish biscuit!");
}

您能否使用 linq 查看两个 IEnumerables 数据是否包含任何公共(public)条目?

最佳答案

是的,您可以使用 Intersect 来做到这一点和 Any :

bool anyCommonEntries = a.Intersect(b).Any();

关于c# - 您能否使用 linq 查看两个 IEnumerables 数据是否包含任何公共(public)条目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5222531/

相关文章:

.net - NuGet 包管理器 - 找不到项目 'Default'。 - Visual Studio 2017

c# - 如何在 linq 中使用带有 2 个字段的 orderby?

c# - Json 属性 C# 的双重标签

c# - 删除 FileSystemWatcher 正在监视的文件夹

c# - 通过 TempData 传递 ViewModel?

c# - 表单可以判断是否有打开的模态窗口吗?

c# - 从客户端应用程序自动安全地登录 Web

C# 编码非托管指针返回类型

c# - 如何将 List<String[]> 转换为 List<int[]>?

c# - 使用 LINQ 在 OrderBy 中自定义排序逻辑