If we implement multiple interfaces in the same class with conflict method names, we don’t need to define all. In other words, we can say if we have conflict methods in the same class, we can’t implement their body independently in the same class because of the same name and same signature. Therefore, we have to use the interface name before the method name to remove this method confiscation. Let’s see an example:
- interface testInterface1 {
- void Show();
- }
- interface testInterface2 {
- void Show();
- }
- class Abc: testInterface1,
- testInterface2 {
- void testInterface1.Show() {
- Console.WriteLine("For testInterface1 !!");
- }
- void testInterface2.Show() {
- Console.WriteLine("For testInterface2 !!");
- }
- }
Now see how to use these in a class:
- class Program {
- static void Main(string[] args) {
- testInterface1 obj1 = new Abc();
- testInterface1 obj2 = new Abc();
- obj1.Show();
- obj2.Show();
- Console.ReadLine();
- }
- }
Output
ASP.NET