[导入]MSIL: call & callvirt

阅读下面的代码,直接说出输出结果。
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();
  }
}

输出:
Two:2
Two:2
One:1

文章来源:http://www.rainsts.net/article.asp?id=719
posted @ 2008-06-20 00:59  橡树木棉狗  阅读(141)  评论(0编辑  收藏  举报