[导入]MSIL: call & callvirt
阅读下面的代码,直接说出输出结果。
输出:
Two:2
Two:2
One:1
文章来源:http://www.rainsts.net/article.asp?id=719
class One
{
private int x = 1;
public virtual void Test()
{
Console.WriteLine("One:" + x);
}
}
class Two : One
{
private int x = 2;
public new void Test()
{
Console.WriteLine("Two:" + x);
}
}
class Three : Two
{
}
class Program
{
static void Main(string[] args)
{
var o = new Three();
o.Test();
(o as Two).Test();
(o as One).Test();
}
}
{
private int x = 1;
public virtual void Test()
{
Console.WriteLine("One:" + x);
}
}
class Two : One
{
private int x = 2;
public new void Test()
{
Console.WriteLine("Two:" + x);
}
}
class Three : Two
{
}
class Program
{
static void Main(string[] args)
{
var o = new Three();
o.Test();
(o as Two).Test();
(o as One).Test();
}
}
输出:
Two:2
Two:2
One:1
文章来源:http://www.rainsts.net/article.asp?id=719