这个电话是从哪里来的?

Ant*_*lov -1 c# il disassembly

我有一些非常类似于以下内容的代码:

class C {
    string s;
    static C a = new C();

    static void Main() {
        C b = a;
        b.s = "hello";
}
Run Code Online (Sandbox Code Playgroud)

Main在发布模式下,该方法的反汇编如下:

        C b = a;
00000000  push        ebp 
00000001  mov         ebp,esp 
00000003  push        eax 
00000004  cmp         dword ptr ds:[04581D9Ch],0 
0000000b  je          00000012 
0000000d  call        763B3BC3 
00000012  xor         edx,edx 
00000014  mov         dword ptr [ebp-4],edx 
00000017  mov         eax,dword ptr ds:[01B24E20h] ; Everything up to this point
0000001c  mov         dword ptr [ebp-4],eax        ; is fairly clear.
        b.s = "hello";
0000001f  mov         eax,dword ptr ds:[01B22088h] ; Loads the address of "hello"
00000025  mov         ecx,dword ptr [ebp-4]        ; Loads the address of b
00000028  lea         edx,[ecx+4]                  ; Loads the address of (the reference to?) b.s
0000002b  call        76100AE0                     ; ??
    }
00000030  nop 
00000031  mov         esp,ebp 
00000033  pop         ebp 
00000034  ret 
Run Code Online (Sandbox Code Playgroud)

我不明白为什么nb的呼叫是必要的.这似乎是的地址b.s,并s作为参数被传递,但由于这是一个简单的指针赋值,为什么是这个必要吗?

(这种行为似乎发生在指针的很多赋值中.但是,赋值null似乎不遵循这种模式.)

usr*_*usr 5

猜测:它设置了一下GC卡表,因为您正在创建从堆字段到堆对象的新引用.

你说"这种行为似乎发生在指针的很多任务上".这非常适合这种解释.