Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

C# - Multiple Inheritance with Interface Example

Sep 21, 2016
Introduction:

Here I will explain how to achieve multiple inheritance in c# with interface example or implement multiple inheritance in c# with example or use interface to implement multiple inheritances in c#, vb.net with example. In c# multiple inheritance can be achieved by using interfaces.

Description:


In c# multi-level inheritance is possible but multiple inheritance is not possible because it will make code more complex. In case if you to implement multiple inheritance in your application we can achieve that by using interfaces.

We will see how to achieve multiple inheritance in c# using interfaces with example.

Example of Multiple Inheritance

Following is the example of implementing multiple inheritance in c# applications using interface.


using System;

namespace inheritanceexample
{
class Program
{
static void Main(string[] args)
{
Operations op = new Operations();
Console.WriteLine("Multiple inheritance using interface\n ");
Console.WriteLine("Result1: " + op.method1(20, 10));
Console.WriteLine("Result2: " + op.method2(100, 50));
Console.WriteLine("Result3: " + op.method3(30, 3));
Console.ReadLine();
}
}
class Operations : inface1, inface2, inface3
{
public int method1(int g, int h)
{
return g + h;
}
public int method2(int i, int j)
{
return i - j;
}
public int method3(int k, int l)
{
return k * l;
}
}
interface inface1
{
int method1(int a, int b);
}
interface inface2
{
int method2(int c, int d);
}
interface inface3
{
int method3(int e, int f);
}
}


Output of Multiple Inheritance Example

Following is the result of multiple inheritance example.

Multiple inheritance in c# using interface example result

I hope it helps you to understand how to achieve multiple inheritance in c# using interface.

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

0 comments :

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.