An implicit implementation of the interface:
Interface IAnimal
{
void Dog ();
}
Class Animal:ianimal
{
public void Dog ()
{
Console.WriteLine ("Dog ...");
}
}
Call through class
Animal Animal = new Animal ();
Animal. Dog ();
or call through the class
Ianimalanimal = new Animal ();
Animal. Dog ();
Interface Display implementation:
Interface IAnimal
{
void Dog ();
}
Class Animal:ianimal
{
void Ianimal.dog ()
{
Console.WriteLine ("Dog ...");
}
}
Can only be called through an interface
IAnimal animal = new animal ();
Animal. Dog ();
Use the method of the class to implement the error, do not allow, "display interface implementation" only allow the implementation of the interface. If you really want to use a class to implement it, you have to do a forced type conversion.
Animal Animal = new Animal ();
(Animal as IAnimal). Dog ();
Adaptive scenarios for display interface implementations and implicit interface implementations
1 . When a class implements an interface, it is usually implemented using an implicit interface, which makes it easy to access interface methods and the methods and properties that the class itself has.
2. When a class implements multiple interfaces, and the interface contains the same method signature, an explicit interface is used to implement it. Even if you do not have the same method signature, it is recommended that you use an explicit interface because you can identify which method belongs to which interface.
3, implicit interface implementations, classes and interfaces are accessible in the interface method. An explicit interface implementation that can only be accessed through an interface.
Implicit and display implementations of C # interfaces