C# 中 Hashtable 類的 Values 屬性是什麼?


Values 屬性可獲取包含 Hashtable 值的 ICollection。

宣告 Hashtable 蒐集 −

Hashtable ht = new Hashtable();

現在新增值

ht.Add("One", "Henry");
ht.Add("Two", "Kevin");
ht.Add("Three", "David");

若要從 Hashtable 顯示值,請使用以下程式碼 −

範例

 線上範例

using System;
using System.Collections;

namespace Demo {
   class Program {
      static void Main(string[] args) {
         Hashtable ht = new Hashtable();

         ht.Add("One", "Henry");
         ht.Add("Two", "Kevin");
         ht.Add("Three", "David");

         // Displaying values
         foreach (string value in ht.Values) {
            Console.WriteLine(value);
         }

         Console.ReadKey();
      }
   }
}

輸出

David
Henry
Kevin

更新日期:20-6 月 -2020

81 瀏覽

啟動您的事業

完成課程即可獲得認證

開始學習
廣告
© . All rights reserved.