[导入][MSIL] 32. Generic

1. Generic Types

我们从简单的入手,试着用 IL 来编写下面这个 C# 泛型演示代码。

C#
class MyClass<T>
{
  public void Test(T o)
  {
    Console.WriteLine(o);
  }
}

MSIL
.class MyClass<T>
{
  .method public specialname void .ctor()
  {
    ldarg.0
    call instance void [mscorlib]System.Object::.ctor()
    ret
  }
  
  .method public void Test(!T o)
  {
    ldarg.1
    box !T
    call PrintObject
    ret
  }
}

文章来源:http://www.rainsts.net/article.asp?id=610
posted @ 2007-10-17 13:35  橡树木棉狗  阅读(93)  评论(0编辑  收藏  举报