Can I use multiple inheritance in C#?

I have a exceptionBase class for application level exception and one data tire base
class.Now I want to create a class which will inherit both the above base classes.
How can I approach thsi?
I am using abstract base classes...
Please suggets me some guide lines.....
regards
ashok
[305 byte] By [AshokKumarRoy] at [2008-2-7]
# 1

It's not possible to inherit from both classes. Most .NET languages do not support multiple inheritance.

What you can do is extract one of the classes out into a interface and inherit that interface.

I have posted a blog entry regarding this:

http://davidkean.net/archive/2005/01/02/216.aspx

DavidM.Kean at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 2

Well if I was you, I would use Interfaces and not classes. You can inherit from both at the same time.

MattSipes at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 3

Hello Ashok,
As David told you, Microsoft .NET Framework Common Language Infrastructure (CLI) Standards Specifications -also known as Common Language Specification (CLS)- indicate that any CLS compliant language (any .NET language) must NOT support multiple inheritance. You cannot inherit more than 1 class, however, you can "implement" any number of interfaces you might want.
For more information and to review the specs., check Microsoft ..NET Framework Common Langauge Runtime (CLR) section at MSDN .NET Framework Developer Center. Also, read Brad Abrams blog post on the .NET CLS.
As a good practice, I'd advise you to replace your abstract classes with interfaces. Not only in this particular case, but, most of the time, so that the classes can explicitly implement these interfaces even if each of them is inherited from another class. Use abstract class as a base whenever you do NOT want the class that implements your abstract members (inherits your abstract class) to be a child of any other class (inherit another class).
I hope that you do like that behavior.
Most regards,

MohamedA.Meligy at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 4
Yeah I have thought about this some. I would inherit from multiple interfaces. Interfaces work exactly like classes basically.

Example:

class Control
{

}

interface ISerializable
{

}

interface IDataBound
{

}

class MyGrid : Control, ISerializable, IDataBound
{

}

You can aggregate the behavorial characterisitcs of multiple programmatic entities by implementing multiple interfaces.

MattSipes at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 5
Thanks for the http://davidkean.net/archive/2005/01/02/216.aspx post. I see how it will work for methods but does it work for properties as well? Would it be possible for you to send a sample?
mkfl at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 6

Do you mean to ask if interfaces support properties? Yes, interfaces support properties and even events. For example:

public interface IMyInterface {

string MyProperty;

}

public class MyClass : IMyInterface {

public string MyProperty {

get { ... }

set { ... }

}

}

Nimrand at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...
# 7

No sorry I wasn't clear...in Dave's post: http://davidkean.net/archive/2005/01/02/216.aspx he shows how to define an AddOnClass and then call it's method, I wanted to know how this could be achieved for properties (if at all possible).

public class MyMultiConcrete : MyBaseClass, IAddOnClass
{
private AddOnClass _AddOnClass;

public MyMultiConcrete()
{
_AddOnClass = new AddOnClass();
}

public void MyAddOnMethod()
{
_AddOnClass.MyAddOnMethod();
}
}

mkfl at 2007-9-8 > top of Msdn Tech,Visual C#,Visual C# Language...