Passing ReadOnlyCollection using the AsReadonly method so that user cannot modify the list
Posted on 10/10/2007 4:21:33 AM
in #ASP.NET 2.X
Hi, This was new to me so as always I decided to share with all. The generic List has a method AsReadonly. The methods can be used if you want to pass the list as readonly. The return value of the method is a ReadOnlyCollection. The ReadOnlyCollection acts as a wrapper around the list. The only difference of a readonlycollection and a list is that a readonlycollection has a wrapper around it which prevents the modification of the collection. If there are changes made to the underlying collection, the changes will be refelected in the readonly collection. Let’s say you have a private collection (list) and want to expose it as read only format. This is when this method will be useful. Vikram
|