No, C# does not support multiple inheritance. Through interface, you can achieve multiple inheritance.
Example
public interface MyInterface1{
int Add(int i, int j);
}
public interface MyInterface2
{
int Sub(int i, int j);
}
public class Math : MyInterface1, MyInterface2
{
public int Add(int i, int j)
{
return i + j;
}
public int Sub(int i, int j)
{
return i - j;
}
}
class Program
{
static void Main(string[] args)
{
Math obj = new Math();
int i = obj.Add(20, 10);
Console.WriteLine(i);
int j = obj.Sub(20, 10);
Console.WriteLine(j);
}
}
No comments:
Post a Comment