Solved

Multiple Inheritance

Posted on 2003-12-08
5
690 Views
Last Modified: 2010-04-16
Can A Form/Control ..anything, inherit more than one thing?
0
Comment
Question by:derekthornton
  • 3
5 Comments
 
LVL 18

Expert Comment

by:testn
ID: 9896907
Nope, .NET doesn't have multiple inheritance feature as of .NET 1.1
0
 
LVL 7

Expert Comment

by:TransBind
ID: 9896961
C# supports single class inheritance only.  Therefore, you can specify only one base class to inherit from.  However, it does allow multiple interface inheritance.
0
 
LVL 7

Accepted Solution

by:
TransBind earned 500 total points
ID: 9897020
An interface looks like a class, but has no implementation.  The only thing it contains are definitions of events, indexers, methods and/or properties.  The reason interfaces only provide definitions is because they are inherited by classes and structs, which must provide an implementation for each interface member defined.


public class DumpTruck: IEngine, IBody
{

void IEngine.Test()
{
Console.WriteLine("This is the Engine TEst");
}
void IBody.Test()
{
Console.WriteLine("This is the Body TEst");
}
}
0
 
LVL 7

Assisted Solution

by:TransBind
TransBind earned 500 total points
ID: 9897037
Another example for u

1:  //  Multi.cs -
 2:  //-----------------------------------------------------------
 3:
 4:  using System;
 5:
 6:  public interface IShape
 7: {
 8:     // Cut out other methods to simplify example.
 9:     double Area();
10:     int Sides { get; }
11:  }
12:
13:  public interface IShapeDisplay
14:  {
15:     void Display();
16:  }
17:
18:  public class Square : IShape, IShapeDisplay
19:  {
20:     private int InSides;
21:     public  int SideLength;
22:
23:     public int Sides
24:     {
25:        get { return InSides; }
26:     }
27:
28:     public double Area()
29:     {
30:        return ((double) (SideLength * SideLength));
31:     }
32:
33:     public double Circumference()
34:     {
35:        return ((double) (Sides * SideLength));
36:     }
37:
38:     public Square()
39:     {
40:        InSides = 4;
41:     }
42:
43:     public void Display()
44:     {
45:        Console.WriteLine("\nDisplaying Square information:");
46:        Console.WriteLine("Side length: {0}", this.SideLength);
47:        Console.WriteLine("Sides: {0}", this.Sides);
48:        Console.WriteLine("Area: {0}", this.Area());
49:     }
50:  }
51:
52:  public class Multi
53:  {
54:     public static void Main()
55:     {
56:        Square mySquare = new Square();
57:        mySquare.SideLength = 7;
58:
59:        mySquare.Display();
60:     }
61:  }

Output
Displaying Square information:
Side length: 7
Sides: 4
Area: 49

0
 
LVL 2

Author Comment

by:derekthornton
ID: 9897120
Er,sorry, didn't see it was the same person both times. I split the points, but I guess that doesn't make a difference, Lol! Thanks.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Angular - break the dataset in chunks? 7 53
ASP.NET 5 Templates 2 81
Where can I ask about my ASP.NET MVC project? 6 38
transaction in asp.net, sql server 6 37
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question