Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / March 2006

Tip: Looking for answers? Try searching our database.

Generic Lists Desing Issue

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
medo - 22 Mar 2006 11:01 GMT
Generic Lists are great!
But 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.
johan.appelgren@gmail.com - 22 Mar 2006 11:08 GMT
Take a look at System.Collections.ObjectModel.Collection<T>
<http://msdn2.microsoft.com/en-US/library/ms132397(VS.80).aspx>.
Mattias Sjögren - 22 Mar 2006 19:56 GMT
>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.

Actually it was, or at least performance is one of the reasons the
List<T> methods are non-virtual. See this post for example

http://blogs.msdn.com/brada/archive/2004/04/25/120055.aspx

Mattias

Signature

Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.