473,394 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,394 software developers and data experts.

Inherit more than on class

(I just started to learn C#.NET)

What's the syntax in c# for a class to inherit more than one class.
I know following syntax:
public class MyClass : MyOtherClass
{
}
but I need to inherit one more class.
Something like this won't work:
public class MyClass : MyOtherClass : MyAnotherClass
{
}

neither does this
public class MyClass : MyOtherClass, MyAnotherClass
{
}

so could someone give me a hint.

And by the way does anyone know any good resources on internet to learn C#.

Thanks.
Nov 15 '05 #1
4 27410
Hi,

In C# you cannot inherit from mroe than one class. You can inherit from one
and implement several interfaces, though.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Slavyan" <sl*****@hotmail.com> wrote in message
news:e2**************@TK2MSFTNGP11.phx.gbl...
(I just started to learn C#.NET)

What's the syntax in c# for a class to inherit more than one class.
I know following syntax:
public class MyClass : MyOtherClass
{
}
but I need to inherit one more class.
Something like this won't work:
public class MyClass : MyOtherClass : MyAnotherClass
{
}

neither does this
public class MyClass : MyOtherClass, MyAnotherClass
{
}

so could someone give me a hint.

And by the way does anyone know any good resources on internet to learn C#.
Thanks.

Nov 15 '05 #2
Slavyan <sl*****@hotmail.com> wrote:
(I just started to learn C#.NET)

What's the syntax in c# for a class to inherit more than one class.


You can't. .NET has single inheritence of implementation, but multiple
inheritence of interface. In other words, you can do:

// Inherit from one class, and implement two interfaces
public class Foo : Stream, IDisposable, IComparable
{
....
}

but you can't do

public class Foo : StreamReader, XslTransformer
{
....
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 15 '05 #3
You can only inherit from ONE class, but you can implement
many interfaces. The syntax is

public class MyClass : MyBaseClass, IMyInterface
{
}

Tu-Thach

-----Original Message-----
(I just started to learn C#.NET)

What's the syntax in c# for a class to inherit more than one class.I know following syntax:
public class MyClass : MyOtherClass
{
}
but I need to inherit one more class.
Something like this won't work:
public class MyClass : MyOtherClass : MyAnotherClass
{
}

neither does this
public class MyClass : MyOtherClass, MyAnotherClass
{
}

so could someone give me a hint.

And by the way does anyone know any good resources on internet to learn C#.
Thanks.
.

Nov 15 '05 #4
As has been pointed out, you can only inherit from one class at a
time, but there is no real limit to the number of linear inherits you
can perform. So, if you need a blue 4-door convertible, you can:

class vehicle {...}

class car : vehicle {...}

class 4doorCar : car {...}

class 4DoorConvertible : 4doorCar {...}

class blue4DoorConvertible : 4doorConvertible {...}

Forgive my overly simplistic example, but you get the point. People
will pick nits about most of that example inheritence chain should
really be properties of Car, but again... you get the point.

If you *REALLY* need multiple inheritence, you need to use C++, but it
can SERIOUSLY kick you in the rear end. The rule of thumb in multiple
inheritence is NEVER inherit from similar classes.

For instance "Thing" can inherit from Tomatoe and Buick, but you
wouldn't want to inherit from Tomatoe and Cucumber. The idea is you
want to keep any overlaps in functionality or interfaces to an
absolute minimum, and completely eliminate them where possible. Then
you have a whole issue with precedence in virtual function
dispatching, etc. It's messy.
"Slavyan" <sl*****@hotmail.com> wrote in message news:<e2**************@TK2MSFTNGP11.phx.gbl>...
(I just started to learn C#.NET)

What's the syntax in c# for a class to inherit more than one class.
I know following syntax:
public class MyClass : MyOtherClass
{
}
but I need to inherit one more class.
Something like this won't work:
public class MyClass : MyOtherClass : MyAnotherClass
{
}

neither does this
public class MyClass : MyOtherClass, MyAnotherClass
{
}

so could someone give me a hint.

And by the way does anyone know any good resources on internet to learn C#.

Thanks.

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sebastian Dau | last post by:
Hey, I'm looking for the right syntax to inherit my class from an Interface and a class at the same time: __interface ITest { };
0
by: djus | last post by:
Hello At the begining I'm sorry for my English :( I want my aspx page TestPage.aspx to inherit from MyClass2. MyClass2 inherits from MyMainClass which is subtype of Page: public class...
6
by: mister.mwa | last post by:
Hello, I have the following problem: I have a class Foo, and a class Bar. I want Foo to inherit from Bar, but i want to put them in separate files Foo.vb and Bar.vb. Then i will use the Foo...
3
by: ad | last post by:
We can inherited a class. but when a class has a .aspx ahead, can we inherit the class and it's .aspx together?
4
by: ABC | last post by:
I want define a base class as: class abc { class cde { } } when I inhert abc class,
3
by: cagenix | last post by:
I was running through a data structures book and I was curious if anyone could inform me of how to inherit the vector class to do a simple search and erase function. The example states: ...
2
by: aia | last post by:
i want to inhert atemplate class example: template<class t> class list { protected: t data; list* nextptr; public: void push()=0;
11
by: Nathan Laff | last post by:
I have a class called Company. I now want to make for one particular app a CompanyEx class, which will inherit from Company. So class CompanyEx: Company how do I set the base? kind of...
1
by: designchemist | last post by:
Is is possible to have one style sheet (sheet1.css) that has a class of .titleText inherit the class that is in another stylesheet (sheet2.css)? Something like... .titleText { url: sheet2.css,...
11
by: Chris | last post by:
Hi, I'm kind of new to the more involved workings of javascript, and am having a few problems. My problem is this: I am working with a CMS which is including various javascrip files in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.