Amit Soni
We have two interfaces with the same method name and return type. can anybody tell me how to implement these two in same class.
By Amit Soni in ASP.NET on Mar 20 2007
  • Sarath Babu
    Mar, 2007 23

    Try this in web application

    interface IClass1{void method1();}

    interface IClass2{void method1();}

    public partial class MyTestPage : System.Web.UI.Page,IClass1,IClass2

    {

    protected void Page_Load(object sender, EventArgs e)

    {

    ((IClass1)this).method1();

    ((IClass2)this).method1();

    }

    void IClass1.method1()

    {

    Response.Write("Class1 method1");

    }

    void IClass2.method1()

    {

    Response.Write("Class2 method1");

    }

    }

    Sarath babu G

    • 0
  • Amit Soni
    Mar, 2007 20

    Interface Ihello1

    {

         void hello();

    }

    Interface Ihello2

    {

         void hello();

    }

    public class Imphello : Ihello1,Ihello2

    {

          void Ihello1.hello()

    {

      console.Writeline("interface 1 hello");

    }

       void Ihello2.hello()

    {

      console.Writeline("interface 2 hello");

    }

    public static void Main()

    {

           Imphello obj = new Imphello();

          obj.Ihello1.hello();

         obj.Ihello2.hello();

    }

    }

    /*but it throw error that Ihello1.hello() and Ihello2.hello(); not present in the class.

    one more thing we have to implement this without creating two instances like Ihello1 obj = new Imphello(); and Ihello2 obj = new Imphello();  give the ans */

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS