Loading ...

Which interface is implemented?

Who is online?  0 guests and 1 members
home  »  forums   »  asp.net topics   »  getting started / general asp.net   » Which interface is implemented?

Which interface is implemented?

Posts under the topic: Which interface is implemented?

Posted: 9/12/2010

Starter 1414  points  Starter
  • Joined on: 12/1/2008
  • Posts: 66

Hello,

i have a question regarding Interface. There are 2 interface both contain the same Method Test().
Now i'm inherting both the interface in Sample class. I want to check method from which interface will be called?
How can i check this?

using System; namespace Interface { interface A { void Test(); } interface B { void Test(); } class Sample: I1, I2 { public void Test() { Console.WriteLine("Which interface will be implemented I1 or I2???!"); } } class Program { public static void Main(string[] args) { Sample t = new Sample(); A a = (A)t; a.Test(); B b = (B)t; b.Test(); Console.ReadLine(); } } }


Thanks,
Sumit


tags Interface, class, c#

Posted: 9/12/2010

Contributor 2237  points  Contributor
  • Joined on: 9/24/2009
  • Posts: 172

Sumit I think Interface B is called.


Posted: 9/12/2010

Guru 16813  points  Guru
  • Joined on: 4/19/2009
  • Posts: 490
  Answered

SumitArora said:

user="Sumit Arora"]class Sample: I1, I2

These are A and B not I1 and I2 according to your sample.

SumitArora said:

user="Sumit Arora"] A a = (A)t; B b = (B)t;

Second no need to type cast it will do it automatically. You can just write A a= t and B b =t

For your original question please refer this: http://www.codeasp.net/blogs/raghav_khunger/microsoft-net/936/c-two-interfaces-with-same-name-and-signature


tags C#
Page 1 of 1 (3 items)