Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Hi what is the mechanism for which I could use to add functions to lists of certain classes? I'm guessing that there is one.

 

So I want these lists to have some of the same functions:

List (of Class1)

List (of Class2)

List (of Class3)

 

The specific functions I'd want to add are like:

.GetObjectFromName

.GetIndexFromName

 

So Each of Class1, Class2, and Class3 have a variable named "Name"

 

I know about how to use interfaces but I'm not sure about how add an interface with a pre-existing class or collection object.

 

Thanks

Edited by NeuralJack
Currently Using: Visual Basic.Net 2005, .Net Framework 2.0
  • Administrators
Posted

Just to clarify a couple of things...

 

Firstly each of the classes expose the same methods (or a least some of the methods are the same) that need to be moved to an interface - correct?

 

Secondly you would like to be able to create a generic List object that could contain any of these objects - also correct?

 

If so you would just need to define a new interface that contains the relevant methods and get each of your existing classes to implement this interface. This will probably require a little bit of editing in VB to make sure each of the existing methods is followed by the relevant Implements statement as well...

 

Generics can be restricted to classes that implement a particular Interface as explained by marble_eater in this post

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...