C# 中 Hashtable 类的 IsReadOnly 属性是什么?


Hashtable 类的 IsReadOnly 属性用于获取一个指示 Hashtable 是否只读的值。

示例

 实际演示

using System;
using System.Collections;
namespace Demo {
   class Program {
      static void Main(string[] args) {
         Hashtable ht = new Hashtable();
         ht.Add("One", "Amit");
         ht.Add("Two", "Aman");
         ht.Add("Three", "Raman");
         Console.WriteLine("IsReadOnly = " + ht.IsReadOnly);
         Console.ReadKey();
      }
   }
}

输出

IsReadOnly = False

以上我们在一个 Hashtable 中设置了三个元素

ht.Add("One", "Amit");
ht.Add("Two", "Aman");
ht.Add("Three", "Raman");

然后,我们使用 IsReadOnly 属性进行了检查

Console.WriteLine("IsReadOnly = " + ht.IsReadOnly);

更新时间: 2020 年 6 月 23 日

88 次浏览

开启你的 事业

通过完成课程获得认证

开始
广告
© . All rights reserved.