Generics: Inheritance and Interface questions

G

Guest

Hi,
I would like to know two things about generics:

1. Can an interface be gerneric? I want the implementing class to be
generic, so the interface has to be.

2. I have a gerneric class, which I want to use as a base class for my own.
But in the subclass I do now the exact type which will be processed and I
don't want anyone to have the ability of changing this. Is it possible to
extend a gerneric base class with a non-gerneric class? And if so, how?

Thanks a lot..

Stampede
 
O

Oliver Sturm

Stampede said:
1. Can an interface be gerneric? I want the implementing class to be
generic, so the interface has to be.

Yes, no problem.
2. I have a gerneric class, which I want to use as a base class for my own.
But in the subclass I do now the exact type which will be processed and I
don't want anyone to have the ability of changing this. Is it possible to
extend a gerneric base class with a non-gerneric class? And if so, how?

Sure, easily. Like this:

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



Oliver Sturm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top