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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top