Posted: 9/12/2010
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
Sumit I think Interface B is called.
SumitArora said: user="Sumit Arora"]class Sample: I1, I2
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;
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