I have a code some thing below.
interface IFirst
{
void Show();
}
public class Test : IFirst
{
void IFirst.Show()
{
Console.WriteLine("First");
}
}
Here in the implementation class i cannot provide public access specifier for Show().
How can i call this Show() from main program?
Explicit interfaces methods can only be accessed through the interface and not through the class that implement them.
In your code, you can cast an instance of your class to the interface and then reference the method/property that was explicitly defined.
MSDN Link on Explicit Interface:
http://msdn.microsoft.com/en-us/library/ms173157%28v=vs.100%29.aspx
Another question asking a similar thing:
Compilation Error: "The modifier 'public' is not valid for this item" while explicitly implementing the interface