उदाहरण 1: पूर्णांक SortedSets का इंटरसेक्शन
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
SortedSet set1 = new SortedSet();
set1.Add(100);
set1.Add(200);
set1.Add(300);
SortedSet set2 = new SortedSet();
set2.Add(450);
set2.Add(200);
set2.Add(650);
set2.Add(300);
set2.Add(800);
Console.WriteLine("क्या इसमें समान तत्व हैं? = " + set1.SetEquals(set2));
set1.IntersectWith(set2);
Console.WriteLine("परिणामी SortedSet...");
foreach(int val in set1) {
Console.WriteLine(val);
}
}
}
आउटपुट
क्या इसमें समान तत्व हैं? = False
परिणामी SortedSet...
200
300
उदाहरण 2: स्ट्रिंग SortedSets का इंटरसेक्शन
using System;
using System.Collections.Generic;
public class Demo {
public static void Main() {
SortedSet set1 = new SortedSet();
set1.Add("AB");
set1.Add("BC");
set1.Add("CD");
set1.Add("EF");
set1.Add("PQ");
set1.Add("ST");
Console.WriteLine("SortedSet1 में तत्व...");
foreach (string res in set1) {
Console.WriteLine(res);
}
Console.WriteLine("SortedSet1 में तत्वों की संख्या = " + set1.Count);
SortedSet set2 = new SortedSet();
set2.Add("BC");
set2.Add("CD");
set2.Add("DE");
set2.Add("EF");
set2.Add("AB");
set2.Add("HI");
set2.Add("JK");
Console.WriteLine("SortedSet2 में तत्व (SortedSet के लिए एन्यूमरेटर)...");
SortedSet.Enumerator demoEnum = set2.GetEnumerator();
while (demoEnum.MoveNext()) {
string res = demoEnum.Current;
Console.WriteLine(res);
}
Console.WriteLine("SortedSet2 में तत्वों की संख्या = " + set2.Count);
set1.IntersectWith(set2);
Console.WriteLine("परिणामी SortedSet...");
foreach(string val in set1) {
Console.WriteLine(val);
}
}
}
आउटपुट
SortedSet1 में तत्व...
AB
BC
CD
EF
PQ
ST
SortedSet1 में तत्वों की संख्या = 6
SortedSet2 में तत्व (SortedSet के लिए एन्यूमरेटर)...
AB
BC
CD
DE
EF
HI
JK
SortedSet2 में तत्वों की संख्या = 7
परिणामी SortedSet...
AB
BC
CD
EF