code
1
using
System;
2
using
System.Collections.Generic;
3
using
System.Linq;
4
using
System.Text;
5
6
namespace
EffectiveCSharpItem23
7
{
8
interface
IMsg
9
{
10
void
Message();
11
}
12
13
public
class
MyClass : IMsg
14
{
15
public
void
Message()
16
{
17
Console.WriteLine(
"
MyClass
"
);
18
}
19
}
20
21
public
class
MyDerivedClass : MyClass, IMsg
22
{
23
public
new
void
Message()
24
{
25
Console.WriteLine(
"
MyDerivedClass
"
);
26
}
27
}
28
29
class
Program
30
{
31
static
void
Main(
string
[] args)
32
{
33
MyDerivedClass d
=
new
MyDerivedClass();
34
d.Message();
35
IMsg m
=
d
as
IMsg;
36
m.Message();
37
38
MyClass c
=
d
as
MyClass;
39
c.Message();
40
}
41
}
42
}
转载于:https://www.cnblogs.com/zhtf2014/archive/2011/02/14/1954639.html
转载请注明原文地址: https://win8.8miu.com/read-1450523.html