The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Generics and object collections

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Eric Gunnerson

Posts: 1006
Nickname: ericgu
Registered: Aug, 2003

Eric Gunnerson is a program manager on the Visual C# team
Generics and object collections Posted: Sep 3, 2003 11:12 PM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Eric Gunnerson.
Original Post: Generics and object collections
Feed Title: Eric Gunnerson's C# Compendium
Feed URL: /msdnerror.htm?aspxerrorpath=/ericgu/Rss.aspx
Feed Description: Eric comments on C#, programming and dotnet in general, and the aerodynamic characteristics of the red-nosed flying squirrel of the Lesser Antilles
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Eric Gunnerson
Latest Posts From Eric Gunnerson's C# Compendium

Advertisement

In VS2003, since we don't have generics, we have lots of strongly-typed collections. For example, there's the LinkCollection class, which holds objects of type Link.

Now that we have generics, we could replace such collections with:

List<Link>

(well, actually, we couldn't replace them, as that would break existing code, but we could do that for new collections). That seems like a simple solution, but it isn't optimal, for a couple of reasons:

  1. Sometimes the type in the collection isn't sufficiently distinctive, especially if it's a built-in type. You'd like to see something like EmployeeIDCollection rather than List<int>
  2. It's often useful to add additional functionality to the collection beyond what you get from the built-in collection class.

The better solution is to define your own collection class. Nicely, you can base it off of the collection class:

class EmployeeIDCollection: List<int>
{
   ...
}

The design guideline is not to expose collection classes, but rather to expose custom collection classes (I really need a better name for those) instead.

 

 

 

Read: Generics and object collections

Topic: Pragmatic Practioners Denver Previous Topic   Next Topic Topic: PM Duties: A new awakening

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use