473,382 Members | 1,749 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

constrained generic base class AND implementing an interface

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
1 4702
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tony Johansson | last post by:
Hello! If you compare an abstract baseclass and an Interface and you only look at the datamembers what exactly is that differ or is the same. For example can you have datamember in both or just...
1
by: MKoleoso | last post by:
Problem: C#- Unable to create instance of a class implementing from an interface I have: namespace someNamespace { public __gc class SomeClass1 { }
2
by: Robb Sadler | last post by:
I am trying to write several hardware interfaces that would use the same base class and functions and be implemented differently. I don't want to ship all of the interfaces, but want to access...
10
by: Brett | last post by:
I'm still trying to figure out concrete reasons to use one over the other. I understand the abstract class can have implementation in its methods and derived classes can only inherit one abstract...
1
by: rapataa | last post by:
Hi, I'm trying to write a generic base class to loop through data and fill my collection objects. The thing is that the base class doesn't know the type of the object I guess. The code should...
1
by: | last post by:
There is a base class that implements an interface. If I inherit that base class will I also inherit the interface?
2
by: AdawayNoSpam | last post by:
Said that I have the following class Class MyRootClass(Of T) End Class Class MySubClass1(Of T) Inherits MyRootClass(Of T) End Class
0
by: purplepangolin | last post by:
I have a generic base class and need a list to contain different types of objects that derive from this. Public class genericBase<T> where T: ConfigBase{} I have tried :...
1
by: Anton Zinchenko | last post by:
I have an abstract generic class: public abstract class SomeBaseClass<U,V> { } I want to create other generic class: public abstract class SomeOtherBaseClass<T1, T2> where...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.