Shieldt describes two reasons for the explicit implementation of interface members, but I don’t understand one of them. Here is what he writes: when the interface method is implemented with its full name, then this method is not available through the class objects that implements this interface, but by the interface reference. Therefore, an explicit implementation allows the interface method to be implemented in such a way that it does not become an open member of the class providing its implementation. I do not understand the meaning of the described and the reason when it should be used and why? The book gives the following example, also I marked the comments that I do not understand also in the code:
interface IEven { bool IsOdd(int x); bool IsEven(int x); } class MyClass : IEven { bool IEven.IsOdd(int x) { if((x%2) != 0) return true; else return false; } // Normal implementation. public bool IsEven(int x) { IEven o = this; //объясните данный участок кода return !o.IsOdd(x); } } class Demo { static void Main() { MyClass ob = new MyClass(); bool result; result = ob.IsEven(4); if(result) Console.WriteLine("4 is even."); // result = ob.IsOdd(4); // Error, IsOdd not exposed. IEven iRef = (IEven) ob; // объясните данный участок кода result = iRef.IsOdd(3); if(result) Console.WriteLine("3 is odd."); }