123
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ExplicitInterfaces { class Program { static void Main(string[] args) { SomeClass sc = new SomeClass(); sc.Draw(); // accessible as public SomeClass2 sc2 = new SomeClass2(); // sc2.Draw(); // not accessible as public IDrawToForm intfForm = (IDrawToForm)sc2; intfForm.Draw(); } } public interface IDrawToForm { void Draw(); } public interface IDrawToMemory { void Draw(); } public interface IDrawToPrinter { void Draw(); } public class SomeClass: IDrawToForm, IDrawToMemory, IDrawToPrinter { public void Draw() { /*123*/ } // << problem! One implementation for all interfaces } public class SomeClass2 : IDrawToForm, IDrawToMemory, IDrawToPrinter { void IDrawToPrinter.Draw() // private access { /*some Implementation1*/ //throw new NotImplementedException(); } void IDrawToMemory.Draw() // private access { /*some Implementation2*/ //throw new NotImplementedException(); } void IDrawToForm.Draw() // private access { /*some Implementation3*/ //throw new NotImplementedException(); } } } |