ex-08-05

来自「Programming Csharp Source Code(代码) Prog」· 代码 · 共 79 行

TXT
79
字号
//Example 08-05: Explicit implementation

using System;

interface IStorable
{
    void Read();
    void Write();
}

interface ITalk
{
    void Talk();
    void Read();
}

// Simplify Document to implement only IStorable
public class Document : IStorable, ITalk
{
    // the document constructor
    public Document(string s) 
    {
         Console.WriteLine("Creating document with: {0}", s);
        
    }
    
    // Make read virtual
    public virtual void Read()
    {
         Console.WriteLine("Implementing IStorable.Read");        
    }

    public void Write()
    {
         Console.WriteLine("Implementing IStorable.Write");        
        
    }

    void ITalk.Read()
    {
        Console.WriteLine("Implementing ITalk.Read");
    }

    public void Talk()    
    {
        Console.WriteLine("Implementing ITalk.Talk");
    }

}


public class Tester
{
 
    static void Main()
    {
        // create a document object
        Document theDoc = new Document("Test Document");
        IStorable isDoc = theDoc as IStorable;
        if (isDoc != null)
        {
            isDoc.Read();
        }

        ITalk itDoc = theDoc as ITalk;
        if (itDoc != null)
        {
            itDoc.Read();
        }

        theDoc.Read();
        theDoc.Talk();

    }

}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?