⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex-08-05

📁 Programming Csharp Source Code(代码) Programming Csharp Source Code
💻
字号:
//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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -