So my friend said that explicitly implemented interface methods are private.
Consider this example for the argument:
interface ITest
{
void Test();
}
class Test : ITest
{
// IS THIS METHOD PRIVATE?
void ITest.Test()
{
Console.WriteLine("What am I?");
}
}
I did not believe that and I will list the arguments on both sides:
Him:
- You cannot specify any access modifiers on an explicitly implemented method and if no access modifier is specified, it will use the lowest possible which should be private hence the method is private.
- In this interview at around 30:30 it sounds as they say that explicitly implemented method can be private which I do believe (I mean it's Mads Torgensen) but I don't why that would be the case.
Me:
- You cannot access the
Test
method from inside the class unless you cast yourself toITest
(which is how explicitly implemented methods work but shouldn't you be able to call the method from inside the class if it really was a private method inside that class?) - When you cast a
Test
-instance toITest
, theTest
method becomes publicly available and can be called from anywhere hence it cannot be private. - I don't know how credible this is but in this answer it is stated that "explicitly implemented interface member" are public.
I think we both know how Explicit Interface Implementation works and how to use it but right here we aren't sure who's right.
The question really boils down to this:
Can you call the Test
method in the Test
class a "private method"?