473,241 Members | 1,767 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,241 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 27401
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: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.