Considerations for the interface:
1) interfaces are implementations, and abstract methods are inherited
2) You can have common methods in the class that implements the interface
3) Define the interface using the keyword Internet
4) Implement Interface without keywords
5) Multiple interfaces can be implemented at one time
Example code:
Interface 1
public interface IFly
{
void Fly ();
}
Interface 2
public interface Irun
{
void Run ();
}
Implementing interfaces
public class Plan:ifly,irun
{
public void Fly ()
{
Console.WriteLine ("Plan Fly");
}
public void Run ()
{
Console.WriteLine ("RUN");
}
public void Eat ()//Common method
{
Console.WriteLine ("Eat");
}
}
Implementing interfaces
public class Brid:ifly
{
public void Fly ()
{
Console.WriteLine ("Fly");
}
}
Test class:
static void Main (string[] args)
{
list<ifly> list = new list<ifly> ()
{
New Brid (),
New Plan ()
};
foreach (IFly item in list)
{
Item. Fly ();
}
Console.readkey ();
}
Interfaces in C #