[导入][MSIL] 32. Generic
1. Generic Types
我们从简单的入手,试着用 IL 来编写下面这个 C# 泛型演示代码。
C#
MSIL
文章来源:http://www.rainsts.net/article.asp?id=610
我们从简单的入手,试着用 IL 来编写下面这个 C# 泛型演示代码。
C#
class MyClass<T>
{
public void Test(T o)
{
Console.WriteLine(o);
}
}
{
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
}
}
{
.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