Interface is a type. Its purpose is to make plug-n-play component e.g. USB on laptop. Now many things can be connected on this USB place.
For polymorphism, interfaces are also used. This is also called Run-time polymorphism.
The name of built-in interfaces starts with “I”. In interface, there is only declaration but no definition.
interface MyFirstApplicationInterface
{
int LogId{get;set;}
void Save();
void Cancel();
}
Note that in interface, we cannot write anything in get and set methods like in LogId property.
If we implement 2 interfaces which have 1 method with same name then to implement this method, we would have to mention InterfaceA.Save() to implement InterfaceA’s Save method. For example,
public class MyClass: InterfaceA, InterfaceB
{
public void InterfaceA.Save()
{
...
}
}