The implementation of IEnumerable <T> and IEnumerable.GetEnumerator () may not be publicly available, why?
To implement an interface member, the corresponding implementation class member must be publicly available. source: Interfaces (C # Programming Guide)
I know this works if its personal, but I would like to understand why it cannot be publicly available?

+4
1 answer
When explicitly implemented interface methods are public by default and why you cannot use access modifiers.
Quote from msdn.com:
When an element is explicitly implemented, an instance of the class cannot be accessed, but only through an instance of the interface (which is public by default)
: https://msdn.microsoft.com/en-us/library/aa288461%28v=vs.71%29.aspx
P.S. :
interface MyInterface
{
void MyMethod();
}
class A : MyInterface // Implicit implementation
{
public void MyMethod () { ... }
}
class B: MyInterface // Explicit implementation
{
void MyInterface.MyMethod () { ... }
}
+9