- SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

C# Interface

C# Interface

shape Description

C# Interface are much like abstract classes which does not allow to create an instance of class. Interface is a replacement of multiple inheritance which helps to avoid name ambiguity and a way to achieve run time polymorphism. The important thing to remember about interfaces is that the classes can only implement the methods defined in the interface. Interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members such as abstract method.

shape Declaration

Interfaces are declared using the interface keyword. It is similar to class declaration. Interface statements by default are public . Following is an example of an interface declaration:

shape Example

[csharp] using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace SPlessons { class Program:def { static void Main(string[] args) { System.Console.WriteLine("Hello Interfaces"); Program refDemo = new Program(); def refdef = refDemo; refdef.xyz(); refdef.pqr(); } public void xyz() { System.Console.WriteLine("In xyz"); } public void pqr() { System.Console.WriteLine("In pqr"); } } interface abc { void xyz(); } interface def : abc { void pqr(); } } [/csharp] Output: