Re: Generic Collections



Scott M. <smar@xxxxxxxxxxxxx> wrote:
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

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@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk
.



Relevant Pages

  • Re: Generic Collections
    ... 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, ... Inherits Generic.List ... World class .NET training in the UK: http://iterativetraining.co.uk ...
    (microsoft.public.dotnet.framework.clr)
  • Re: Wrapping DAO, for better or worse
    ... As some of you may recall, I have marching orders to implement wrapper classes in VB.Net to implement a DAO-like interface so that we can evolve our legacy VB6 app from DAO to SQL Server, and eventually the app itself to .Net. ... I have a nearly functional version of these wrappers working and for the most part, things seem to work very well. ... Inherits CollectionBase ...
    (microsoft.public.dotnet.languages.vb)
  • ICollection implementation
    ... I have a class which inherits from CollectionBase. ... void ICollection.CopyTo(Array array, int index) ... containing class does not implement interface ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Create a custom collection
    ... I would typically solve this using a class that inherits from CollectionBase ... custom Objects, add a Key property and an ID property. ... > DictionaryBase. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: collections?
    ... Assuming you're using 2005 the simplest thing is to use generics ... Public Class ContactCollection ... Inherits System.Collections.Generic.List ... If you're using 2003 you should inherit CollectionBase. ...
    (microsoft.public.dotnet.languages.vb.controls)

Loading