-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplicit_interfaces.cs
41 lines (39 loc) · 1016 Bytes
/
explicit_interfaces.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System;
namespace InterfaceImplementation
{
interface I1
{
void InterfaceMethod();
}
interface I2
{
void InterfaceMethod();
}
class Program : I1, I2
{
static void Main(string[] args)
{
I2 p2 = new Program();
I1 p1 = new Program();
//if a class inherites from 2 or more interfaces with same method use explicit interface typecasting
Program p = new Program();
p.InterfaceMethod();
((I1)p).InterfaceMethod();
((I2)p).InterfaceMethod();
p2.InterfaceMethod();
p1.InterfaceMethod();
}
//public void InterfaceMethod()
//{
// Console.WriteLine("I2 Interface Method");
//}
public void InterfaceMethod()
{
Console.WriteLine("I1 Interface Method");
}
void I2.InterfaceMethod()
{
Console.WriteLine("I2 Interface Method");
}
}
}