【发布时间】:2012-10-12 17:53:18
【问题描述】:
我现在正在使用 IL 代码,将来需要自己编写。由于误解,我有些担心。这是C#中的一个简单方法
public static string Method1(int id)
{
return Method2(id);
}
这是它的 IL 代码
.method public hidebysig static string
Method1(int32 id) cil managed
{
//
.maxstack 1
.locals init ([0] string CS$1$0000)
IL_0000: nop // Why?
IL_0001: ldarg.0
IL_0002: call string MyNamespace.MyClass::Method2(int32)
IL_0007: stloc.0 // storing a return value of MyClass::Method2 to local variable.
IL_0008: br.s IL_000a // Why?
IL_000a: ldloc.0 // Does it really require and why?
IL_000b: ret
} // end of method MyClass::Method1
由于某种原因,CIL 中的 每个 方法都有nop 操作。为什么会有它?
在我的情况下,是否有必要使用br.s IL_000a,没有它是否可以工作?
【问题讨论】:
-
“自己写”,你会写IL吗?
-
我已经发布了 IL 应该作为对同行答案的编辑