C# 程序,从两个或更多列表中找出公共值
创建多个列表 −
// two lists
var list1 = new List<int>{3, 4};
var list2 = new List<int>{1, 2, 3};现在,使用 Intersect() 方法获取公共值 −
var res = list1.Intersect(list2);
以下是完整代码 −
示例
using System.Collections.Generic;
using System.Linq;
using System;
public class Demo {
public static void Main() {
// two lists
var list1 = new List<int>{3, 4};
var list2 = new List<int>{1, 2, 3};
// common values
var res = list1.Intersect(list2);
foreach(int i in res) {
Console.WriteLine(i);
}
}
}输出
3
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C #
MongoDB
MySQL
Javascript
PHP