Wednesday, February 23, 2011

Best Coding Practice - Don't expose collection as a property

It is common in coding that if we have to expose a collection inside a class we normally declare a property of IList. But this approach has many pit falls. The one simple reason is any one can alter the values inside the collection. Which may not be desired by the class.

So right approach is to use

System.Collections.ObjectModel.ReadOnlyCollection<xxx> to declare the property.

No comments:

Post a Comment