multiple base classes workaround

N

Nigil Chua

Hi Guys,

I would like to inherited the MethodCls for both MasterPage and Page
But got the multiple base interface exception.

pubilc class MethodCls
{
}

public class Master:System.Web.UI.MasterPage,MethodCls
{
}

public class Page:System.Web.UI.Page,MethodCls
{
}


My Closest is solution is as follow. am I doing the correct way? or can
interface solve my issues as well?
cos I would like the MethodCls to reflect both Master and Page classes.

pubilc class MethodCls
{
}

public class Master:System.Web.UI.MasterPage
{
MethodCls _MethodCls=new MethodCls();

public MethodCls MyMethod
{
get{return _MethodCls;}
set {_MethodCls=value;}
}
}

public class Page:System.Web.UI.Page
{
MethodCls _MethodCls=new MethodCls();

public MethodCls MyMethod
{
get{return _MethodCls;}
set {_MethodCls=value;}
}
}


Best Regards.
Nigil Chua
 
P

Peter Duniho

I would like to inherited the MethodCls for both MasterPage and Page
But got the multiple base interface exception.

Exception? Or compiler error? It should be the latter, and when you're
dealing with programmers being precise is important. :)
pubilc class MethodCls
{
}

public class Master:System.Web.UI.MasterPage,MethodCls
{
}

public class Page:System.Web.UI.Page,MethodCls
{
}


My Closest is solution is as follow. am I doing the correct way? or can
interface solve my issues as well?
cos I would like the MethodCls to reflect both Master and Page classes.

C# doesn't support multiple inheritance. You can only inherit one class.
However, you can inherit multiple interfaces so yes, using one or more
interfaces would be a way to address this. You can either declare a base
class that implements both interfaces, or you can declare two base classes
each of which provide the implementation for an interface and then use
composition in a new class to get the implementation from those classes
into a third class that implements both interfaces.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top