Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> C#

C# में SortedSet में किसी विशिष्ट तत्व की जांच कैसे करें

C# में SortedSet किसी विशिष्ट तत्व को रखता है या नहीं, यह जांचने के लिए Contains() मेथड का उपयोग किया जाता है। यह मेथड एक बूलियन मान लौटाता है।

उदाहरण 1

using System;
using System.Collections.Generic;

public class Demo {
    public static void Main() {
        SortedSet set1 = new SortedSet();
        set1.Add("CD");
        set1.Add("CD");
        set1.Add("CD");
        set1.Add("CD");

        Console.WriteLine("SortedSet1 में तत्व...");
        foreach (string res in set1) {
            Console.WriteLine(res);
        }
        Console.WriteLine("क्या SortedSet1 में तत्व DE है? = " + set1.Contains("DE"));

        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 में तत्व...");
        foreach (string res in set2) {
            Console.WriteLine(res);
        }
        Console.WriteLine("क्या SortedSet2, SortedSet1 का सुपरसेट है? = " + set2.IsSupersetOf(set1));
    }
}

आउटपुट

SortedSet1 में तत्व...
CD
क्या SortedSet1 में तत्व DE है? = False
SortedSet2 में तत्व...
AB
BC
CD
DE
EF
HI
JK
क्या SortedSet2, SortedSet1 का सुपरसेट है? = True

उदाहरण 2

using System;
using System.Collections.Generic;

public class Demo {
    public static void Main() {
        SortedSet mySet = new SortedSet();
        mySet.Add(100);
        mySet.Add(200);
        mySet.Add(300);
        mySet.Add(400);

        Console.WriteLine("SortedSet में तत्व...");
        foreach (int res in mySet) {
            Console.WriteLine(res);
        }
        Console.WriteLine("क्या SortedSet में तत्व 400 है? = " + mySet.Contains(400));
    }
}

आउटपुट

SortedSet में तत्व...
100
200
300
400
क्या SortedSet में तत्व 400 है? = True
  1. - C# में Queue में किसी तत्व की जांच कैसे करें

    C# में Queue किसी विशिष्ट तत्व को रखता है या नहीं, यह जांचने के लिए Contains() मेथड का उपयोग किया जाता है। यह मेथड एक बूलियन मान लौटाता है। उदाहरण 1 using System; using System.Collections.Generic; public class Demo { public static void Main() { Queue queue = new Queue(); queue.E

  1. - C# में Collection में किसी तत्व की जांच कैसे करें

    C# में Collection<T> किसी विशिष्ट तत्व को रखता है या नहीं, यह जांचने के लिए Contains() मेथड का उपयोग किया जाता है। यह मेथड एक बूलियन मान लौटाता है। उदाहरण 1 using System; using System.Collections.ObjectModel; public class Demo { public static void Main() { Collection col = new Col

  1. - C# में HashSet में निर्दिष्ट तत्व है या नहीं जांचें

    C# में HashSet किसी विशिष्ट तत्व को रखता है या नहीं, यह जांचने के लिए Contains() मेथड का उपयोग किया जाता है। यह मेथड एक बूलियन मान लौटाता है। उदाहरण 1 using System; using System.Collections.Generic; public class Demo { public static void Main() { HashSet set1 = new HashSet(); se