By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,763 Members | 1,385 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,763 IT Pros & Developers. It's quick & easy.

constrained generic base class AND implementing an interface

P: n/a
what is the syntax for implementing an interface in a generic class
that has a constrained base class

example:

class myclass<T>: mybase<T> where T: IComparable
{
}

Now, I want myclass<T> to implement IMyInterface. What is the syntax
for this?

class myclass<T>:mybase<T> where T:IComparable, IMyInterface - doesnt
work because this says that the class 'mybase<T>' has an additional
constraint on T

class myclass<T>:IMyInterface, mybase<T> where T:IComparable - doesnt
work because base classes must come before any interfaces that are
implemented.

So how do I tell the compiler that I want myclass<T> to implement the
interface IMyInterface when it is a sub class of mybase<T> where T is
constained?

Apr 3 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
class myclass<T>: mybase<T>,IMyInterface where T: IComparable
"ProjectNut" <da*************@raytheon.com> ha scritto nel messaggio
news:11**********************@v46g2000cwv.googlegr oups.com...
what is the syntax for implementing an interface in a generic class
that has a constrained base class

example:

class myclass<T>: mybase<T> where T: IComparable
{
}

Now, I want myclass<T> to implement IMyInterface. What is the syntax
for this?

class myclass<T>:mybase<T> where T:IComparable, IMyInterface - doesnt
work because this says that the class 'mybase<T>' has an additional
constraint on T

class myclass<T>:IMyInterface, mybase<T> where T:IComparable - doesnt
work because base classes must come before any interfaces that are
implemented.

So how do I tell the compiler that I want myclass<T> to implement the
interface IMyInterface when it is a sub class of mybase<T> where T is
constained?

Apr 3 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.