Interfaces in C #
Interface
[Public | protected | private] interface InterfaceName
{
// Mothed
// Propery
// Event
// Delegate
}
Differences between interfaces with and without Interfaces
Without the difference eg:
Public interface IMyShow
{
Void Show ();
}
Public class MyShow: IMyShow
{
Public void Show () // you must write the previous public statement. If the file is written as void Show (), an error occurs.
{
System. Console. Write ("without Interface Name ");
}
}
Public class MyMain
{
Public static void Main ()
{
// Reference with Class Definition
MyShow obj = new MyShow ();
Obj. Show ();
// Use the interface to reference the Method
IMyShow obj2 = new MyShow ();
Obj2.Show ();
}
}
// With the Interface Name
Public interface IMyShow
{
System. Console. Write ("with Interface Name ");
}
Public class MyShow: IMyShow
{
Void IMyShow. Show () // no prefix is allowed
{
System. Console. Write ("with Interface Name ");
}
}
Public class MyMain
{
Public static void Main ()
{
MyShow obj = new MyShow ();
Obj. Show (); // invalid because a qualified word is added, this method is a reference of the experts and can only be referenced by interfaces.
IMyShow obj2 = new MyShow ();
Obj2.Show ();
}
}
After reading the above content, I want to leave a question for C # hobbies. Let's discuss it together.
Public interface IMyShow
{
Void Show ();
}
Public interface IMyShow2
{
Void Show ();
}
Public class Myclass: IMyShow, IMyShow2
{
Public Myclass ()
{
}
Void IMyShow. Show ()