using Generics

T

Tony

Hello!

I just wonder in .NET 2.0 Generics was added.
Before generics existed it was an advantage to get strongly typed methods so
we derived collection classes from CollectionBase
where we had to implement add remove and so on.

But now when generic classes can be used I can't see any point in ever using
this CollectionBase any more.

Do you agree with me?

//Tony
 
J

Jon Skeet [C# MVP]

I just wonder in .NET 2.0 Generics was added.
Before generics existed it was an advantage to get strongly typed methods so
we derived collection classes from CollectionBase
where we had to implement add remove and so on.

But now when generic classes can be used I can't see any point in ever using
this CollectionBase any more.

Do you agree with me?

There's little reason to use the nongeneric CollectionBase. However,
there are additional reasons to use something *like* CollectionBase
(and I can't remember the generic equivalent right now) - if you want
to be able to validate items as they are added, hook up events etc.

Jon
 
M

Marc Gravell

However,
there are additional reasons to use something *like* CollectionBase
(and I can't remember the generic equivalent right now)

Probably System.Collections.ObjectModel.Collection<T>

Unlike List<T>, this has virtual methods as extension points.

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top