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

सी # में ऑर्डर्ड डिक्शनरी कैसे बनाएं?

C# में एक OrderedDictionary बनाने के लिए, कोड इस प्रकार है -

उदाहरण

using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
   public static void Main() {
      OrderedDictionary dict = new OrderedDictionary();
      dict.Add("A", "Books");
      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 elements...");
      foreach(DictionaryEntry d in dict) {
         Console.WriteLine(d.Key + " " + d.Value);
      }
      Console.WriteLine("Count of elements in OrderedDictionary = " + dict.Count);      
      dict.Remove("E");
      Console.WriteLine("Count of elements in OrderedDictionary (Updated)= " + dict.Count);
   }
}

आउटपुट

यह निम्नलिखित आउटपुट देगा -

OrderedDictionary elements...
A Books
B Electronics
C Smart Wearables
D Pet Supplies
E Clothing
F Footwear
Count of elements in OrderedDictionary = 6
Count of elements in OrderedDictionary (Updated)= 5

उदाहरण

आइए एक और उदाहरण देखें -

using System;
using System.Collections;
using System.Collections.Specialized;
public class Demo {
   public static void Main() {
      OrderedDictionary dict = new OrderedDictionary();
      dict.Add("1", "One");
      dict.Add("2", "Two");
      dict.Add("3", "Three");
      dict.Add("4", "Four");
      dict.Add("5", "Five");
      dict.Add("6", "Six");
      dict.Add("7", "Seven");
      dict.Add("8", "Eight");
      ICollection col = dict.Keys;
      String[] strKeys = new String[dict.Count];
      col.CopyTo(strKeys, 0);
      Console.WriteLine("Displaying the keys...");
      for (int i = 0; i < dict.Count; i++) {
         Console.WriteLine(strKeys[i]);
      }
   }
}

आउटपुट

यह निम्नलिखित आउटपुट देगा -

Displaying the keys...
1
2
3
4
5
6
7
8

  1. PowerPoint में एक रेडियल सूची कैसे बनाएं

    पलक झपकते ही अपने दर्शकों का ध्यान आकर्षित करने के लिए एक सूची बनाना चाहते हैं? आप Microsoft PowerPoint . में एक रेडियल सूची बना सकते हैं अपनी प्रस्तुति को आकर्षक रूप देने के लिए। रेडियल सूची ग्राफिक रूप से एक केंद्रीय विचार बनाने के लिए एक साथ आने वाले भागों को दिखाती है। PowerPoint में रेडियल सूची

  1. पावरपॉइंट में टाइमलाइन कैसे बनाएं

    एक समयरेखा चार्ट घटनाओं की एक श्रृंखला का एक चित्रमय प्रतिनिधित्व है, उदाहरण के लिए, किसी व्यक्ति के जीवन की मुख्य घटनाएं या किसी परियोजना में मील का पत्थर। अपनी टाइमलाइन बनाने के बाद, आप तिथियां जोड़ और स्थानांतरित कर सकते हैं, विभिन्न शैलियों और लेआउट जोड़ सकते हैं और टाइमलाइन का रंग बदल सकते हैं।

  1. आप पायथन में नेस्टेड डिक्ट कैसे बनाते हैं?

    आप नेस्टेड सिंटैक्स का उपयोग करके एक नेस्टेड डिक्शनरी बना सकते हैं, ठीक वैसे ही जैसे आप किसी JSON ऑब्जेक्ट को परिभाषित करते हैं। उदाहरण a = {    'foo': 45,    'bar': {       'baz': 100,      'tru': "Hello" &n