I was reading about implicit or explicit interface methods implementation, but I still not understand how it works and what are the benefits.
Having the code:
interface InterfaceOne
{
void MethodOne();
}
class ClassOne : InterfaceOne
{
public void MethodOne()
{
Console.WriteLine("hello from the class method");
}
void InterfaceOne.MethodOne()
{
Console.WriteLine("hello from the interface method");
}
}
And the code from the main method:
var c1 = new ClassOne();
c1.MethodOne();
InterfaceOne i1 = new ClassOne();
i1.MethodOne();
Console.ReadLine();
And here is the output:
hello from the class method
hello from the interface method
My questions:
Why I don't have an error having a class with two methods with the same name and signature?
When I'm using var keyword, how does the compiler choses which method to call?
What are the benefits?