Read-only hashtable

  • Thread starter Thread starter Raghu
  • Start date Start date
R

Raghu

The HashTable object exposes IsReadOnly property from IDictionary interface
(default is false). I have a hashtable that I want expose in a method call.
However I do not want the user to remove or add any items to it. Is there a
way to use this property so that user won't change the items in the
collection. First of all, I have not even see how you set this property to
true. Does any one know how to set this property to true?

Thanks.
Raghu/..
 
Raghu said:
The HashTable object exposes IsReadOnly property from IDictionary interface
(default is false). I have a hashtable that I want expose in a method call.
However I do not want the user to remove or add any items to it. Is there a
way to use this property so that user won't change the items in the
collection. First of all, I have not even see how you set this property to
true. Does any one know how to set this property to true?

Hashtable always returns false for IsReadOnly because the Hashtable class
doesn't provide any read-only functionality.

IsReadOnly, Add(), Remove(), Item(), etc. are all virtual. You can override
them to provide a read-only hash table and use that derived type as your
method's return type.
 
Back
Top