Is it possible to do something like this in C# :
C#
public class MyClass implements ClassA extends ClassB { }
I need this because: I have two classes, one of which is Interface , which I will implement in my class, but I would also like to use methods from another class that do some things that I would like to use in my class.
Interface
C # does not support multiple inheritance . You can get one class and use interfaces for other needs.
Syntax:
class MyClass : Foo, IFoo, IBar { } interface IFoo { } interface IBar { } class Foo { }
Try the following:
using System; public interface A { void DoSmth(); } public class B { public void OpA() { } public void OpB() { } } public class ClassC : B, A { public void DoSmth(){} }
Remember that you cannot inherit two classes at a particular class level, it can be only one class and any number of interfaces.
class Base { } interface I1 { } interface I2 { } class Derived : Base, I1, I2 { } static void Main(String[] args) { Derived d = new Derived(); }
It should look like this:
public class MyClass: ClassB, InterfaceA{ }
Class B is the base class.
An interface is an interface.
You can extend only one base class, but you can implement many interfaces.