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”。

posted on 2004-10-29 17:45  魏巍  阅读(1257)  评论(0)    收藏  举报

导航