C# 中 Hashtable 类的 IsReadOnly 属性是什么?
csharpprogrammingserver side programming更新于 2025/10/12 3:37:17
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
上面我们设置了一个包含三个元素的哈希表。
ht.Add("One", "Amit");
ht.Add("Two", "Aman");
ht.Add("Three", "Raman");
之后,我们使用 IsReadOnly 属性进行了检查。
Console.WriteLine("IsReadOnly = " + ht.IsReadOnly);

