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.