About multi-Inherits

  • Thread starter Thread starter Jet Leung
  • Start date Start date
J

Jet Leung

Hi all,
I had made a UserControl, and I want to inherits panel,label,button and
linklabel from my class. But when I typed the code like
====
public class A :
System.Windows.Forms.UserControl,System.Windows.Forms.Panel,
System.Windows.Forms.Button,System.Windows.Forms.Label,System.
Windows.Forms.LinkLabel
.....

======

There is an error to me. It said thoes were not interface,and I couldn't
inherits them.

How can I solve this problem?
 
Hello Jet,

C# does not support multiple inheritance of classes, only interfaces. Since
they are not interfaces, you get this error.
You can't solve this problem - unless you inherit interfaces.

Good luck,

Razzie
 
Hi Jet,

You can only inherit from one single class in C#.
You can, however, inherit from multiple interfaces and the syntax to do so is how you wrote your class

public class A : BaseClass, Interface1, Interface2, Interface3 ...
{
}

So the compiler expects Panel, Button, Label, linkLabel to be interfaces, which they are not.

You need to rethink your strategy. Why do you want to inherit from all the classes.
 
I had made a UserControl, and I want to inherits panel,label,button and
linklabel from my class.

Are you sure you don't want your control to *contain* these other
controls? Even if C# and the CLR supported multiple inheritance (which
they don't), what kind of behavior would you expect this control to
have?



Mattias
 
Back
Top