|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Generic Lists Desing IssueBut I think you missed a opportunity. Here is my problem. I made a Collection "Family: List<Person> " which will contain 'Family'. I wanted to override the Add method so you can only add persons whose Parents or Childeren are already in the list, but the Add method is not virtual! The Add method of Arraylist is virtual and I see no reason for the generic counterpart not to be. My work around is to create my own GenericList that has a private List<T> and duplicate all IList<T> members and make them virtual, but still it should have been there all along. I see no reason why List<> or all other generic collections have no virtual methods, is there? Maybe speed, but that wasn't an issue with ArrayList so it shouldn't be with generic collections either. Take a look at System.Collections.ObjectModel.Collection<T>
<http://msdn2.microsoft.com/en-US/library/ms132397(VS.80).aspx>. >I see no reason why List<> or all other generic collections have no virtual Actually it was, or at least performance is one of the reasons the>methods, is there? Maybe speed, but that wasn't an issue with ArrayList so >it shouldn't be with generic collections either. List<T> methods are non-virtual. See this post for example http://blogs.msdn.com/brada/archive/2004/04/25/120055.aspx Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
Other interesting topics
|
|||||||||||||||||||||||