Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / November 2007

Tip: Looking for answers? Try searching our database.

Generic Collections

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Scott M. - 27 Nov 2007 19:33 GMT
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

Since the Generic.List type has Add, Remove, and Item (as well as the Find
methods and other useful collection members) and accessing any particular
item in the collection will return a strong type association to the
underlying object, then what else would I need?
Jon Skeet [C# MVP] - 27 Nov 2007 20:47 GMT
> Given that in .NET 1.x, we could make a strongly-typed collection by
> creating a class that inherited from CollectionBase and implementing custom
[quoted text clipped - 6 lines]
>     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?

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
World class .NET training in the UK: http://iterativetraining.co.uk

Scott M. - 27 Nov 2007 21:50 GMT
Ok thanks.

>> Given that in .NET 1.x, we could make a strongly-typed collection by
>> creating a class that inherited from CollectionBase and implementing
[quoted text clipped - 12 lines]
> unless you're actually adding any functionality to it, why bother
> creating a new class to derive from it?
Barry Kelly - 30 Nov 2007 23:48 GMT
> Given that in .NET 1.x, we could make a strongly-typed collection by
> creating a class that inherited from CollectionBase and implementing custom
[quoted text clipped - 11 lines]
> item in the collection will return a strong type association to the
> underlying object, then what else would I need?

Don't forget Collection(Of T) base class. It has virtual methods to
notify you of changes to the collection, should you be interested in
them, which can be a reason to override.

-- Barry

Signature

http://barrkel.blogspot.com/


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.