Computer >> คอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

รับ ICollection ที่มีคีย์ใน HybridDictionary ใน C #


ในการรับ ICollection ที่มีคีย์ใน HybridDictionary รหัสจะเป็นดังนี้ -

ตัวอย่าง

using System;
using System.Collections.Specialized;
public class Demo {
   public static void Main(){
      HybridDictionary dict = new HybridDictionary();
      dict.Add("One", "Katie");
      dict.Add("Two", "Andy");
      dict.Add("Three", "Gary");
      dict.Add("Four", "Mark");
      dict.Add("Five", "Marie");
      dict.Add("Six", "Sam");
      dict.Add("Seven", "Harry");
      dict.Add("Eight", "Kevin");
      dict.Add("Nine", "Ryan");
      String[] strArr = new String[dict.Count];
      dict.Keys.CopyTo(strArr, 0);
      for (int i = 0; i < dict.Count; i++)
      Console.WriteLine(strArr[i]);
   }
}

ผลลัพธ์

สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

Eight
Seven
Four
Three
One
Five
Six
Two
Nine

ตัวอย่าง

เรามาดูตัวอย่างกัน −

using System;
using System.Collections.Specialized;
public class Demo {
   public static void Main(){
      HybridDictionary dict = new HybridDictionary();
      dict.Add("1", "A");
      dict.Add("2", "B");
      dict.Add("3", "C");
      dict.Add("4", "D");
      dict.Add("5", "E");
      dict.Add("6", "F");
      String[] strArr = new String[dict.Count];
      dict.Keys.CopyTo(strArr, 0);
      for (int i = 0; i < dict.Count; i++)
         Console.WriteLine(strArr[i]);
   }
}

ผลลัพธ์

สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

1
2
3
4
5
6