Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

a collection of generics? (NO CASTING)

Status
Not open for further replies.

Insider1984

Technical User
Joined
Feb 15, 2002
Messages
132
Location
US
Okay, we have an application that needs a collection of generic classes. We thought of having an ArrayList of generic classes but we believe that this involves casting of each generic class in the collection.

A simple understanding:

Each generic class has an event and we would like to call each of these events from the collection of generic classes.

Can we do this without casting.... if so, what is the best way to do it.

=====================
Insider
4 year 'on the fly' programmer
C, C++, C#, MFC, Basic, Java ASP.NET
 
Oh sorry, I should clarify that each of the generic classes in the collection is bound to a different type....



=====================
Insider
4 year 'on the fly' programmer
C, C++, C#, MFC, Basic, Java ASP.NET
 
they all have the same events?

what version of the framework are you using?

Christiaan Baes
Belgium

"My new site" - Me
 
same events, .net 2.0

Thanks.

=====================
Insider
4 year 'on the fly' programmer
C, C++, C#, MFC, Basic, Java ASP.NET
 
if they have the same name then you make an interface and let the classes implment that. And then you make a System.collections.generics.list<interfacename> and voila no more casting.

Christiaan Baes
Belgium

"My new site" - Me
 
Like Chrissie1 says.

You create an Interface that doesn't do anything (no properties or methods), and have your classes implement it. Something like IOurCollection.

You can then have a List<IOurCollection>

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top