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

C# में OrderedDictionary में कुंजी/मान जोड़ों की संख्या प्राप्त करना

उदाहरण 1: OrderedDictionary में तत्व जोड़ना और गिनना

using System;
using System.Collections;
using System.Collections.Specialized;

public class Demo {
    public static void Main() {
        OrderedDictionary dict = new OrderedDictionary();
        dict.Add("A", "Home Appliances");
        dict.Add("B", "Electronics");
        dict.Add("C", "Smart Wearables");
        dict.Add("D", "Pet Supplies");
        dict.Add("E", "Clothing");
        dict.Add("F", "Footwear");

        Console.WriteLine("OrderedDictionary तत्व...");
        foreach(DictionaryEntry d in dict) {
            Console.WriteLine(d.Key + " " + d.Value);
        }
        Console.WriteLine("OrderedDictionary में तत्वों की संख्या = " + dict.Count);
        dict.Clear();
        Console.WriteLine("OrderedDictionary में तत्वों की संख्या (अपडेटेड) = " + dict.Count);
    }
}

आउटपुट

OrderedDictionary तत्व...
A Home Appliances
B Electronics
C Smart Wearables
D Pet Supplies
E Clothing
F Footwear
OrderedDictionary में तत्वों की संख्या = 6
OrderedDictionary में तत्वों की संख्या (अपडेटेड) = 0

उदाहरण 2: दो OrderedDictionary की तुलना और ReadOnly जांच

using System;
using System.Collections;
using System.Collections.Specialized;

public class Demo {
    public static void Main() {
        OrderedDictionary dict1 = new OrderedDictionary();
        dict1.Add("A", "John");
        dict1.Add("B", "Andy");
        dict1.Add("C", "Jacob");
        dict1.Add("D", "Kevin");
        dict1.Add("E", "Gary");
        dict1.Add("F", "Nathan");
        dict1.Add("G", "Kevin");
        dict1.Add("H", "Ryan");

        Console.WriteLine("OrderedDictionary1 तत्व...");
        foreach(DictionaryEntry d in dict1) {
            Console.WriteLine(d.Key + " " + d.Value);
        }
        Console.WriteLine("OrderedDictionary1 में कुंजी-मान जोड़ों की संख्या = " + dict1.Count);

        OrderedDictionary dict2 = new OrderedDictionary();
        dict2.Add("1", "One");
        dict2.Add("2", "Two");
        dict2.Add("3", "Three");
        dict2.Add("4", "Four");
        dict2.Add("5", "Five");
        dict2.Add("6", "Six");

        Console.WriteLine("\nOrderedDictionary2 तत्व...");
        foreach(DictionaryEntry d in dict2) {
            Console.WriteLine(d.Key + " " + d.Value);
        }
        Console.WriteLine("OrderedDictionary2 में कुंजी-मान जोड़ों की संख्या = " + dict2.Count);
        Console.WriteLine("\nक्या OrderedDictionary1, OrderedDictionary2 के बराबर है? = " + (dict1.Equals(dict2)));
        OrderedDictionary orderedDict = dict2.AsReadOnly();
        Console.WriteLine("क्या OrderedDictionary केवल पढ़ने योग्य है? = " + orderedDict.IsReadOnly);
    }
}

आउटपुट

OrderedDictionary1 तत्व...
A John
B Andy
C Jacob
D Kevin
E Gary
F Nathan
G Kevin
H Ryan
OrderedDictionary1 में कुंजी-मान जोड़ों की संख्या = 8
OrderedDictionary2 तत्व...
1 One
2 Two
3 Three
4 Four
5 Five
6 Six
OrderedDictionary2 में कुंजी-मान जोड़ों की संख्या = 6
क्या OrderedDictionary1, OrderedDictionary2 के बराबर है? = False
क्या OrderedDictionary केवल पढ़ने योग्य है? = True
  1. - C# में OrderedDictionary में मानों को समाहित करने वाला ICollection प्राप्त करें

    OrderedDictionary में मानों को समाहित करने वाला ICollection प्राप्त करने के लिए, कोड इस प्रकार है: उदाहरण using System; using System.Collections; using System.Collections.Specialized; public class Demo { public static void Main(){ OrderedDictionary dict = new OrderedDictionary();

  1. Redis HVALS का उपयोग: सभी हैश मान प्राप्त करें Redis HVALS का उपयोग: सभी हैश मान प्राप्त करें

    HVALS कमांड यह कमांड निर्दिष्ट की पर संग्रहीत हैश मान में समाहित सभी फील्ड्स के मान लौटाता है। यदि की मौजूद नहीं है तो एक खाली सूची लौटाई जाती है और यदि की मौजूद है लेकिन की पर संग्रहीत मान हैश डेटाटाइप का नहीं है तो त्रुटि लौटाई जाती है। Redis HVALS कमांड का सिंटैक्स निम्न है: सिंटैक्स: redis host

  1. Redis HLEN कमांड: हैश फील्ड्स की संख्या तुरंत गिनें Redis HLEN कमांड: हैश फील्ड्स की संख्या तुरंत गिनें

    सिंटैक्स: redis host:port> HLEN <key name> आउटपुट: - (पूर्णांक) मान, हैश में फील्ड्स की संख्या दर्शाता है। - 0, यदि की मौजूद नहीं है। - त्रुटि, यदि की मौजूद है और की पर संग्रहीत मान हैश नहीं है। उदाहरण: संदर्भ: HLEN कमांड डॉक्स Redis डेटास्टोर में संग्रहीत हैश मान में समाहित फील्ड्स