Implicit and Explicit implementations for Multiple Interface inheritance
Following C#.NET demo explains you all the scenarios for implementation of Interface methods to classes. There are two ways you can implement a interface method to a class. 1. Implicit Implementation 2. Explicit Implementation. Please go though the sample. using System; namespace ImpExpTest { class Program { static void Main(string[] args) { C o3 = new C(); Console.WriteLine(o3.fu()); I1 o1 = new C(); Console.WriteLine(o1.fu()); I2 o2 = new C(); Console.WriteLine(o2.fu()); var o4 = new C(); //var is considered as C Console.WriteLine(o4.fu()); var o5 = (I1)new C(); //var is considered as I1 Console.WriteLine(o5.fu()); var o6 = (I2)new C(); //var is considered as I2 Console.WriteLine(o6.fu()); D o7 = new D(); Console.WriteLine(o7.fu()); I1 o8 = new D(); Console.WriteLine(o8.fu()); I2 o9 = new D(); Console.WriteLine(o9.fu()); } } interface I1 { string fu(); } interface I2 { string fu(); } class C : I1, I2 { #region Imicitly Defined I1 Members public string fu() { return "Hello C"; } #endregion Imicitly Defined I1 Members #region Explicitly Defined I1 Members string I1.fu() { return "Hello from I1"; } #endregion Explicitly Defined I1 Members #region Explicitly Defined I2 Members string I2.fu() { return "Hello from I2"; } #endregion Explicitly Defined I2 Members } class D : C { #region Imicitly Defined I1 Members public string fu() { return "Hello from D"; } #endregion Imicitly Defined I1 Members } }.csharpcode, .csharpcode pre{ font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/}.csharpcode pre { margin: 0em; }.csharpcode .rem { color: #008000; }.csharpcode .kwrd { color: #0000ff; }.csharpcode .str { color: #006080; }.csharpcode .op { color: #0000c0; }.csharpcode .preproc { color: #cc6633; }.csharpcode .asp { background-color: #ffff00; }.csharpcode .html { color: #800000; }.csharpcode .attr { color: #ff0000; }.csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em;}.csharpcode .lnum { color: #606060; }Output:-Hello C Hello from I1 Hello from I2 Hello C Hello from I1 Hello from I2 Hello from D Hello from I1 Hello from I2
span.fullpost {display:none;}