我正在尝试学习如何If在C#中使用ILGenerator生成语句.
这是我的代码:(ilg是ILGenerator)
ilg.Emit(OpCodes.Ldc_I4_1);
Label start = ilg.DefineLabel();
ilg.Emit(OpCodes.Brfalse, start);
ilg.Emit(OpCodes.Ldstr, "Hello");
ilg.Emit(OpCodes.Call, typeof(Console).GetMethod("WriteLine", new Type[] { typeof(string) }));
ilg.MarkLabel(start);
Run Code Online (Sandbox Code Playgroud)
一些说明:
未处理的异常:System.InvalidProgramException:公共语言运行时检测到无效的程序.在Testing.Test.Main(String [])