Hashtable question

  • 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 this property and you can't change it. It
always returns false because it never provides read-only functionality.

You can create a new class that inherits Hashtable and then override Add,
Remove, Item, IsReadOnly, etc. to create the read-only behavior you're
looking for, and then use this derived class instead of the base Hashtable
class.
 
Back
Top