-
C# |检查 SortedSet 和指定的集合是否共享公共元素
C# |检查 SortedSet 和指定的集合是否共享公共元素
原文:https://www . geesforgeks . org/c-sharp-check-if-sorted set-and-a-specified-collection-share-common-elements/
SortedSet 类表示按排序顺序排列的对象集合。这个班隶属于T3 系统。集合.通用命名空间。排序集合。重叠(IEnumerable )方法 用于检查排序集和指定集合是否共享公共元素。
属性:
- 在 C# 中,SortedSet 类可用于存储、移除或查看元素。
- 它保持升序,不存储重复的元素。
- 如果必须存储唯一元素并保持升序,建议使用 SortedSet 类。
语法:
mySortedSet1.Overlaps(mySortedSet2);
这里我的 ortedSet1 和我的 ortedSet2 是两个排序集。
返回值:如果 mySortedSet1 和 mySortedSet2 共享至少一个公共元素,则函数返回 True ,否则返回 False 。
异常:如果排序集为空,该方法将给出 ArgumentNullException。
例 1:
// C# code to Check if SortedSet
// and a specified collection
// share common elements
using System;
using System.Collections.Generic;
class GFG {
// Driver code
public static void Main()
{
// Creating a SortedSet of integers
SortedSet<int> mySortedSet1 = new SortedSet<int>();
// adding elements in mySortedSet1
mySortedSet1.Add(5);
mySortedSet1.Add(6);
mySortedSet1.Add(7);
mySortedSet1.Add(8);
mySortedSet1.Add(9);
// Creating a SortedSet of integers
SortedSet<int> mySortedSet2 = new SortedSet<int>();
// adding elements in mySortedSet2
mySortedSet2.Add(7);
mySortedSet2.Add(8);
mySortedSet2.Add(9);
mySortedSet2.Add(10);
mySortedSet2.Add(11);
// Check if SortedSet and a specified
// collection share common elements
Console.WriteLine(mySortedSet1.Overlaps(mySortedSet2));
}
}
Output:
True
例 2:
// C# code to Check if SortedSet
// and a specified collection
// share common elements
using System;
using System.Collections.Generic;
class GFG {
// Driver code
public static void Main()
{
// Creating a SortedSet of strings
SortedSet<string> mySortedSet1 = new SortedSet<string>();
// adding elements in mySortedSet1
mySortedSet1.Add("A");
mySortedSet1.Add("B");
mySortedSet1.Add("C");
mySortedSet1.Add("D");
mySortedSet1.Add("E");
// Creating a SortedSet of strings
SortedSet<string> mySortedSet2 = new SortedSet<string>();
// adding elements in mySortedSet2
mySortedSet2.Add("F");
mySortedSet2.Add("G");
mySortedSet2.Add("H");
mySortedSet2.Add("I");
mySortedSet2.Add("J");
// Check if SortedSet and a specified
// collection share common elements
Console.WriteLine(mySortedSet1.Overlaps(mySortedSet2));
}
}
Output:
False
参考:
- https://docs . Microsoft . com/en-us/dotnet/API/system . collections . generic . sorted set-1 .重叠?视图=netframework-4.7.2
版权属于:月萌API www.moonapi.com,转载请注明出处
本文链接:https://www.moonapi.com/news/27936.html
栏目列表
最新更新
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
Python初学者友好丨详解参数传递类型
如何有效管理爬虫流量?
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
SQL Server -- 解决存储过程传入参数作为s
关于JS定时器的整理
JS中使用Promise.all控制所有的异步请求都完
js中字符串的方法
import-local执行流程与node模块路径解析流程
检测数据类型的四种方法
js中数组的方法,32种方法
前端操作方法
数据类型
window.localStorage.setItem 和 localStorage.setIte
如何完美解决前端数字计算精度丢失与数