檢查一個 SortedSet 物件是否為 C# 中指定的集合的真子集
要檢查 SortedSet 物件是否為指定集合的真子集,程式碼如下 −
示例
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(){
SortedSet set1 = new SortedSet();
set1.Add(20);
set1.Add(40);
set1.Add(60);
set1.Add(80);
set1.Add(100);
set1.Add(120);
set1.Add(140);
Console.WriteLine("Elements in SortedSet1...");
foreach (int res in set1){
Console.WriteLine(res);
}
SortedSet set2 = new SortedSet();
set2.Add(20);
set2.Add(40);
set2.Add(60);
Console.WriteLine("Elements in SortedSet2...");
foreach (int res in set2){
Console.WriteLine(res);
}
Console.WriteLine("SortedSet2 is a proper subset of SortedSet1? = "+set2.IsProperSubsetOf(set1));
}
}輸出
這將產生以下輸出 −
Elements in SortedSet1... 20 40 60 80 100 120 140 Elements in SortedSet2... 20 40 60 SortedSet2 is a proper subset of SortedSet1? = True
示例
讓我們看另一個示例 −
using System;
using System.Collections.Generic;
public class Demo {
public static void Main(){
SortedSet set1 = new SortedSet();
set1.Add(20);
set1.Add(40);
set1.Add(60);
Console.WriteLine("Elements in SortedSet1...");
foreach (int res in set1){
Console.WriteLine(res);
}
SortedSet set2 = new SortedSet();
set2.Add(20);
set2.Add(40);
set2.Add(60);
Console.WriteLine("Elements in SortedSet2...");
foreach (int res in set2){
Console.WriteLine(res);
}
Console.WriteLine("SortedSet2 is a proper subset of SortedSet1? = "+set2.IsProperSubsetOf(set1));
}
}輸出
這將產生以下輸出 −
Elements in SortedSet1... 20 40 60 Elements in SortedSet2... 20 40 60 SortedSet2 is a proper subset of SortedSet1? = False
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP