I created and implemented the interface explicitly, as shown below.
public interface IA { void Print(); } public class C : IA { void IA.Print() { Console.WriteLine("Print method invoked"); } }
and then executed by the following main method
public class Program { public static void Main() { IA c = new C(); C c1 = new C(); foreach (var methodInfo in c.GetType().GetMethods(BindingFlags.NonPublic | BindingFlags.Instance)) { if (methodInfo.Name == "ConsoleApplication1.IA.Print") { if (methodInfo.IsPrivate) { Console.WriteLine("Print method is private"); } } } c.Print(); } }
and the result that I got on the console:
Printing method is private
The printing method is called.
So my question is why this private method was executed from another class?
As far as I understand, the accessibility of a private member is limited by his type of announcement, why he behaves so strangely.
source share