The C# programming language introduces a unique feature with which you can combine interfaces. That means two or more interfaces can be combined into a single interface. After that you only need to call the combined interface while inheriting them. In listing 4.7, two interfaces named InterfaceDemo and InterfaceDemo1 are combined into a single interface called CombinedInter. The class MultipleInter extends this interface and provides the implementation of the interface methods. Inside the Main() method, the methods are called by creating an instance of the class.
using System;
interface InterfaceDemo
{
void show();
}
interface InterfaceDemo1
{
void display();
}
interface CombinedInter:InterfaceDemo,InterfaceDemo1
{
//Above interfaces combined
}
class MultipleInter:CombinedInter
{
public void show()
{
Console.WriteLine("show() method Implemented");
}
public void display()
{
Console.WriteLine("display() method Implemented");
}
public static void Main(string[] args)
{
MultipleInter mi = new MultipleInter();
mi.show();
mi.display();
}
}
In this part of the series, you have learned about structures, inheritance and interfaces with the help of source codes and explanations.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |