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.