注意:
1. 不能提供访问控制符;
2. 显示实现的成员总是自动为私有的
示例:
using System;
namespace ExplicitImpleInterfaceTest
{
public interface IDrawToMemory
{
void Draw();
}
public class Triangle : IDrawToMemory
{
void IDrawToMemory.Draw() //此处不能加访问控制符
{
Console.WriteLine("Triangle.Draw...");
}
}
class Program
{
static void Main(string[] args)
{
Triangle triangle = new Triangle();
//triangle.Draw(); //错误
if (triangle is IDrawToMemory)
{
((IDrawToMemory)triangle).Draw();
}
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
}
}
}