接口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();
}
}

posted @ 2016-10-20 14:17  FredGrit  阅读(296)  评论(0编辑  收藏  举报