What is Interface, how to use interface in C#

What is Interface, how to use interface in C#:


For resolve the problem of multiple inheritances, in C# introduce the concept of interface. Interface is a reference type and it contains only abstract method.  Interface member’s can be Events, Methods, Properties, and Indexers. The can only declaration of these members, as like class interface do not provide implementations.  The interface cannot contain data-field, constructor  constants, destructor and static members.

Syntax of interface in C#:

Interface <name of interface>
{
//user code……….
}



Implementation of interface in C#:

The general form of class that implements the inheritance is –
Class <class_name> : <interface_name>
{
}
When we want to implement more the one interface in C# the we can be using coma(,) between to interface when inherit in class as like:-
  Class <class_name> : <interface_name>,<interface2_name>
{
}

Example of interface in C#:

Using System;
Interface myinterface
{
Void show();
}
// interface end.
Class example:myinterface
{
Public void show()
{
Console.writeLine(“hello: I am method of interface”);
}
Public static void main(String [] args)
{
Example e=new example();
e.show();
}
}


Other Post Related to Asp.net and C#:





Comments