• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

collection in the .net framework

We would like to know the best practices for using collection in the .net framework.  We have the following two collections, what are the pros and cons for each.  One is a non generic collection and one is generic colleciton.  Would it be best pracices to use the generic colleciton all the time?

    public class PhoneCollection : CollectionBase
    {
        public void Add(PhoneNumber obj)
        {
            this.List.Add(obj);

        }
        public void Remove(PhoneNumber obj)
        {
            this.List.Remove(obj);
        }
    }

    public class PhoneCollection : List<PhoneNumber>
    {
    }
0
tampsystems
Asked:
tampsystems
  • 2
1 Solution
 
alex_pavenCommented:
The generic versions of collections tend to be more flexible and quite likely faster than using Objects, but it all depends on your specific requirements, of course.
If you are interested in performance and type safety, I'd recommend the generic version.
0
 
tampsystemsAuthor Commented:
what is a good reason to use the non-generic version?
0
 
alex_pavenCommented:
Ummm... actually I can't think of any really good ones. I suppose you'd be forced to not use generics if you target version 1.1 of the framework... or if you want to stuff anything in a collection and use crazy reflection logic to manipulate the objects...
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now