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

更新於: 2020 年 6 月 20 日

81 次瀏覽

快速啟動您的 職業生涯

完成課程獲得認證

開始
廣告
© . All rights reserved.