Define an interface first:
Public Interface ICategory
{
String GetName ();
}
Then implement the interface defined above:
public class Category:icategory
{
public string GetName ()
{
return name;
}
}
The above approach is to implicitly implement the interface (the default is to use an implicit interface)
Explicitly implement the interface mode:
public class Category:icategory
{
public string Icategory.getname ()
{
return name;
}
}
Difference:
1. When implementing an interface implicitly, we have two ways to invoke the method that implements the interface (GetName ()), namely:
ICategory category=new category ();
Category. GetName ();
And
Category category=new category ();
Categoty. GetName ();
2. When explicitly implementing an interface, we have only one way to invoke GetName (), namely:
ICategory category=new category ();
Category. GetName ();
Conclusion:
1. When an interface is implicitly implemented, the interface and class (the class that implements the interface) can access the methods in the class;
2. When an interface is explicitly implemented, only the methods in the class are accessed through the interface;
Explicit Advantages:
1. Hiding the implementation code of the class implementing the interface
Display implementation interface and implicit implementation interface differences