Wednesday, May 09, 2007 9:55 AM dbottjer

DoNotExposeGenericLists recommends Collection<T> over List<T>

DoNotExposeGenericLists is a Code Analysis rule exposed within Visual Studio when List<T> is publically exposed.  For example, List<T> may be exposed through properties, methods, parameters, etc.  Why does DoNotExposeGenericLists recommend that I expose Collection instead of List? [David Kean] explains that Collection<T> is the better choice b/c it exposes 4 overidable methods.  The methods are ClearItems, InsertItem, RemoveItem and SetItem.  Events can be raised from within these four methods to provide a notification when changes are made to the Collection.  

Filed under: , ,

Comments

No Comments