Roadmap › OOP Concepts in C# › Module: Interfaces and Abstract Classes
Lessons in this course (15)
10. Explicit interface implementation
IntermediateMediumLesson 10 of 15
Used when two interfaces have the same member, or to hide a member from the class's public API.
csharp
public interface IPrinter { void Print(); }
public interface IScanner { void Print(); } // same name
public class Mfp : IPrinter, IScanner
{
void IPrinter.Print() => Console.WriteLine("printing");
void IScanner.Print() => Console.WriteLine("printing scan log");
}
var m = new Mfp();
((IPrinter)m).Print(); // only callable through the interface