分类集 类表示按排序顺序排列的对象集合。这门课属于 系统收藏。通用的 名称空间。 分类集
null
属性:
- 在C#中,SortedSet类可用于存储、删除或查看元素。
- 它保持升序,不存储重复的元素。
- 如果必须存储唯一元素并保持升序,建议使用SortedSet类。
语法:
mySortedSet1.SetEquals(mySortedSet2);
在这里 mySortedSet1 和 mySortedSet2 有两个分类集。
返回值: 函数返回 符合事实的 如果 mySortedSet1 和 mySortedSet2 是平等的,否则就会有回报 错误的 .
例外情况: 这种方法会给你 无理例外 如果SortedSet是 无效的 .
例1:
// C# code to Check if SortedSet // and the specified collection // contain the same 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(1); mySortedSet1.Add(2); mySortedSet1.Add(3); mySortedSet1.Add(4); mySortedSet1.Add(5); // Creating a SortedSet of integers SortedSet< int > mySortedSet2 = new SortedSet< int >(); // adding elements in mySortedSet2 mySortedSet2.Add(1); mySortedSet2.Add(2); mySortedSet2.Add(3); mySortedSet2.Add(4); mySortedSet2.Add(5); // Check if SortedSet and the specified // collection contain the same elements Console.WriteLine(mySortedSet1.SetEquals(mySortedSet2)); } } |
输出:
True
例2:
// C# code to Check if SortedSet and // the specified collection // contain the same 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 the specified // collection contain the same elements Console.WriteLine(mySortedSet1.SetEquals(mySortedSet2)); } } |
输出:
False
参考:
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END