C#中接口的使用
public interface ILog
{
int OpenLogFile(string FileName);
int CloseLogFile();
void LogString(string strToLog);
}
class MyLog : ILog
{
int ILog.OpenLogFile(string FileName)
{
Console.WriteLine("Open File {0}", FileName);
return 0;
}
int ILog.CloseLogFile()
{
Console.WriteLine("Close File");
return 0;
}
void ILog.LogString(string strToLog)
{
Console.WriteLine("Logging String {0}", strToLog);
}
static void Main(string[] args)
{
ILog app = new MyLog();
app.OpenLogFile("MyLogFile_00");
app.LogString("Success");
app.CloseLogFile();
}
}
注意:
在C#中,“An explicitly implemented member cannot be accessed through a class instance, but only through an instance of the interface”。


浙公网安备 33010602011771号