Blog Stats
  • Posts - 142
  • Articles - 0
  • Comments - 23
  • Trackbacks - 0

 

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.  


Feedback

No comments posted yet.


Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

 

 

Copyright © DennisBottjer