using Generics

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tony

    using Generics

    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


  • Jon Skeet [C# MVP]

    #2
    Re: using Generics

    On Jun 16, 11:00 am, "Tony" <johansson.ande rs...@telia.com wrote:
    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

    Comment

    • Marc Gravell

      #3
      Re: using Generics

      However,
      there are additional reasons to use something *like* CollectionBase
      (and I can't remember the generic equivalent right now)
      Probably System.Collecti ons.ObjectModel .Collection<T>

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

      Marc

      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: using Generics

        On Jun 16, 12:20 pm, Marc Gravell <marc.grav...@g mail.comwrote:
        However,
        there are additional reasons to use something *like* CollectionBase
        (and I can't remember the generic equivalent right now)
        >
        Probably System.Collecti ons.ObjectModel .Collection<T>
        >
        Unlike List<T>, this has virtual methods as extension points.
        Yup, that's the one :)

        Jon

        Comment

        Working...