【问题标题】:Create a list with the common elements of other lists in C# [duplicate]用C#中其他列表的公共元素创建一个列表[重复]
【发布时间】:2021-02-24 08:55:08
【问题描述】:

我知道如何合并列表,但如果我只想要普通对象?

例子:

List A={1,2,3,4,5}
List B={4,5,6}

我知道如何创建此列表

List C={1,2,3,4,5,4,5,6}

但我想创建这个

List C={4,5}

【问题讨论】:

  • 这是什么语言?它看起来不像 C#。

标签: c# list merge


【解决方案1】:

使用 Linq 和 Intersect 方法:

C = A.Intersect(B)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-04
    • 1970-01-01
    • 1970-01-01
    • 2012-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多