📄 ex-08-05
字号:
//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 + -