接口interface实现与显示实现

接口实现:

interface IMath
{
void Add(int x, int y);
}

public class MathClass : IMath
{
public void Add(int x, int y)
{
Console.WriteLine("This is the interface implementation :{0}+{1}={2}", x, y, x + y);
}
}

class Program
{
static void Main(string[] args)
{
int x = 897, y = 987;
MathClass obj = new MathClass();
obj.Add(x, y);
IMath IObj = new MathClass();
IObj.Add(x, y);
Console.ReadLine();
}

接口显示实现:

interface IMath
{
void Add(int x, int y);
}

public class MathClass : IMath
{
void IMath.Add(int x, int y)
{
Console.WriteLine("This is the explicitly implement the IMath :{0}+{1}={2}", x, y, x + y);
}
}

class Program
{
static void Main(string[] args)
{
int x = 987654, y = 90890;
IMath Obj = new MathClass();
Obj.Add(x, y);
Console.ReadLine();
}
}

原文地址:https://www.cnblogs.com/Fred1987/p/5980680.html