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

C# में जांचना कि क्या Hashtable में कोई विशिष्ट कुंजी मौजूद है

उदाहरण 1: Hashtable में कुंजी जांचना

using System;
using System.Collections;

public class Demo {
    public static void Main() {
        Hashtable hash = new Hashtable();
        hash.Add("One", "Katie");
        hash.Add("Two", "John");
        hash.Add("Three", "Barry");
        hash.Add("Four", "");
        hash.Add("Five", "Harry");
        hash.Add("Six", "F");
        hash.Add("Seven", "Tom");
        hash.Add("Eight", "Andy");
        hash.Add("Nine", "I");
        hash.Add("Ten", "Tim");

        Console.WriteLine("Hashtable कुंजी और मान जोड़े...");
        foreach(DictionaryEntry entry in hash) {
            Console.WriteLine("{0} और {1} ", entry.Key, entry.Value);
        }
        Console.WriteLine("क्या Hashtable का आकार निश्चित है? = " + hash.IsFixedSize);
        Console.WriteLine("क्या Hashtable केवल पढ़ने योग्य है? = " + hash.IsReadOnly);
        Hashtable hash2 = Hashtable.Synchronized(hash);
        Console.WriteLine("क्या Hash सिंक्रनाइज़्ड है? = " + hash2.IsSynchronized);
        Console.WriteLine("क्या Hashtable में कुंजी Ten है? = " + hash.Contains("Ten"));
    }
}

आउटपुट

Hashtable कुंजी और मान जोड़े...
One और Katie
Ten और Tim
Five और Harry
Three और Barry
Seven और Tom
Two और John
Four और
Eight और Andy
Nine और I
Six और F
क्या Hashtable का आकार निश्चित है? = False
क्या Hashtable केवल पढ़ने योग्य है? = False
क्या Hash सिंक्रनाइज़्ड है? = True
क्या Hashtable में कुंजी Ten है? = True

उदाहरण 2: मौजूद न होने वाली कुंजी जांचना

using System;
using System.Collections;

public class Demo {
    public static void Main() {
        Hashtable hash = new Hashtable();
        hash.Add("1", "AB");
        hash.Add("2", "BC");
        hash.Add("3", "DE");
        hash.Add("4", "EF");
        hash.Add("5", "GH");
        hash.Add("6", "IJ");
        hash.Add("7", "KL");
        hash.Add("8", "MN");
        hash.Add("9", "OP");
        hash.Add("10", "QR");

        Console.WriteLine("कुंजी 3 पर मान = " + hash["3"]);
        Console.WriteLine("क्या Hashtable में कुंजी 12 है? = " + hash.Contains("12"));
    }
}

आउटपुट

कुंजी 3 पर मान = DE
क्या Hashtable में कुंजी 12 है? = False
  1. - C# में Hashtable में किसी विशिष्ट मान की जांच कैसे करें

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

  1. - C# में Hashtable का निश्चित आकार है या नहीं जांचें

    C# में Hashtable का आकार निश्चित है या नहीं, यह जांचने के लिए IsFixedSize प्रॉपर्टी का उपयोग किया जाता है। यह प्रॉपर्टी एक बूलियन मान लौटाती है। Hashtable का आकार कभी निश्चित नहीं होता, इसलिए यह हमेशा false लौटाता है। उदाहरण 1 using System; using System.Collections; public class Demo { public s

  1. - C# Program: Check Whether a List is Empty or Not

    C# में Elements Store और Fetch करने के लिए Lists का उपयोग करें। आइए एक Example देखते हैं।Exampleusing System; using System.Collections.Generic; public class Demo {    public static void Main(string[] args) {       var subjects = new List();       subjects.Add(