注意:
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();
}
}
}