Hello Folks,
I was exploring the explicit interface implementation and got a question.
In the example below public void ITest.TestMethod() gives error however void ITest.TestMethod() works.
May I know the reason?
interface ITest
{
void TestMethod();
}
class TestClass: ITest
{
//public void ITest.TestMethod() //Error The modifier 'public' is not valid for this item
void ITest.TestMethod() //Works
{
Console.WriteLine("Explicit Interface Implementation");
}
}

Guest UserPosted Apr 24, 2015, 3:33 PM
Prakash TripathiPosted Apr 24, 2015, 1:24 PM
Guest UserPosted Apr 22, 2015, 4:47 AM
Quote: "An interface member that is explicitly implemented cannot be accessed from a class instance:"
Because you use explicit implementation, you cannot give it an access specifier, the method can only be called by using the interface, not the class instance.