-
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
栏目列表
最新更新
博克-定制图例
博克-注释和图例
Bokeh–添加小部件
向博克图添加标签
将交互式滑块添加到博克图
在 Bokeh 中添加按钮
谷歌、微软、Meta?谁才是 Python 最大的金
Objective-C语法之代码块(block)的使用
URL Encode
go语言写http踩得坑
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
SQL Server -- 解决存储过程传入参数作为s
[SQL Server]按照设定的周别的第一天算任意
Linux下定时自动备份Docker中所有SqlServer数
六、Danfo.js 数据可视化
五、plotly.js 数据可视化
四、数据分析、清理、转化
三、Danfo.js 入门
第二部分:使用 Danfo.js 和 Dnotebook 的据分
一、现代 JavaScript 概述
javascript 第一部分:基础知识
零、前言
uni-app开发跨平台小程序开发的诸多坑【转
前端设计模式——桥接模式