Re: List's Add and Remove are not virtual. What now?
Chris Tavares <[email protected]> Wed, 30 Jan 2008 14:27:22 -0800
| Newsgroups | gmane.comp.windows.devel.dotnet.clr |
|---|---|
| Message-ID | <001501c8638f$49563a00$dc02ae00$@com> |
Don't inherit directly from List<T>. Instead, inherit from System.Collections.ObjectModel.Collection<T>. As the help says: "Provides the base class for a generic collection." This class has virtual InsertItem, SetItem, and RemoveItem methods that let you customize how stuff is added or removed from the collection. As long as your consuming code uses IList<T>, ICollection<T> instead of List<T> directly you should be fine. -Chris -----Original Message----- From: Discussion of development on the .NET platform using any managed language [mailto:[email protected]] On Behalf Of Brady Kelly Sent: Wednesday, January 30, 2008 2:08 PM To: [email protected] Subject: [DOTNET-CLR] List's Add and Remove are not virtual. What now? I would have like to override these methods in my class derived of List<T>. Is there some base list somewhere I could use to the same effect, and why shouldn't these be overridden? =================================== This list is hosted by DevelopMentor. http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com