gpt4 book ai didi

field - 为什么在调用 MSIL 中的字段之前必须执行 ldarg.0?

转载 作者:行者123 更新时间:2023-12-03 11:36:48 25 4
gpt4 key购买 nike

我想调用一个函数,参数为 string和一个 Int32 . string只是一个文字,Int32应该是 field .所以我认为它应该是这样的:

.method public hidebysig instance string TestVoid() cil managed
{
.maxstack 1
.locals init (
[0] string CS$1$0000)
L_0000: nop
L_0001: ldstr "myString"
L_0006: ldfld int32 FirstNamespace.FirstClass::ByteField
L_000b: call string [Class1]Class1.TestClass::Functie<int32>(string, int32)
L_0010: ret
}

但这会引发错误,即这不是有效代码。添加时
ldarg.0 

之前 ldfld它运行得很好。为什么会这样,当拥有更多字段时,这是否会给我带来麻烦?

最佳答案

实例方法有一个称为“this”的隐式参数。它作为第一个参数加载到堆栈中,因此您有 ldarg.0 用于“this”。

关于field - 为什么在调用 MSIL 中的字段之前必须执行 ldarg.0?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1785372/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com