all groups > dotnet clr > november 2007 >
You're in the

dotnet clr

group:

Generic Collections


Generic Collections Scott M.
11/27/2007 2:33:23 PM
dotnet clr: Given that in .NET 1.x, we could make a strongly-typed collection by
creating a class that inherited from CollectionBase and implementing custom
Add, Remove, and Item members that only work for a given type and that now,
with Generics we don't need to do that extra work, does it mean that to
fully implement a strongly typed Generic collection in .NET 2.0, I need
nothing more than something like this:

Public Class foo(Of T)
Inherits Generic.List(Of T)
End Class

Since the Generic.List type has Add, Remove, and Item (as well as the Find
methods and other useful collection members) and accessing any particular
item in the collection will return a strong type association to the
underlying object, then what else would I need?
Re: Generic Collections Scott M.
11/27/2007 4:50:29 PM
Ok thanks.


[quoted text, click to view]
Re: Generic Collections Jon Skeet [C# MVP]
11/27/2007 8:47:55 PM
[quoted text, click to view]

You don't even need that. Just use List(Of T) directly in your code -
unless you're actually adding any functionality to it, why bother
creating a new class to derive from it?

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
Re: Generic Collections Barry Kelly
11/30/2007 11:48:13 PM
[quoted text, click to view]

Don't forget Collection(Of T) base class. It has virtual methods to
notify you of changes to the collection, should you be interested in
them, which can be a reason to override.

-- Barry

--
AddThis Social Bookmark Button