Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If we take a look at the jitted code, we'll see that <code>str2</code> is assembled using <code>String.Concat</code> and that it in fact is not the same reference as <code>str1</code>. We will also see that the comparison is done using <code>Equals</code>. In other words the assert passes as the strings contain the same characters. </p> <p>This code</p> <pre><code>static void Main(string[] args) { string str1 = "foofoo"; string strFoo = "foo"; string str2 = strFoo + strFoo; Console.WriteLine(str1 == str2); Debugger.Break(); } </code></pre> <p>is jitted to (please scroll sideways to see comments)</p> <pre><code>C:\dev\sandbox\cs-console\Program.cs @ 22: 00340070 55 push ebp 00340071 8bec mov ebp,esp 00340073 56 push esi 00340074 8b3530206003 mov esi,dword ptr ds:[3602030h] ("foofoo") &lt;-- Note address of "foofoo" C:\dev\sandbox\cs-console\Program.cs @ 23: 0034007a 8b0d34206003 mov ecx,dword ptr ds:[3602034h] ("foo") &lt;-- Note different address for "foo" C:\dev\sandbox\cs-console\Program.cs @ 24: 00340080 8bd1 mov edx,ecx 00340082 e81977fe6c call mscorlib_ni+0x2b77a0 (6d3277a0) (System.String.Concat(System.String, System.String), mdToken: 0600035f) &lt;-- Call String.Concat to assemble str2 00340087 8bd0 mov edx,eax 00340089 8bce mov ecx,esi 0034008b e870ebfd6c call mscorlib_ni+0x2aec00 (6d31ec00) (System.String.Equals(System.String, System.String), mdToken: 060002d2) &lt;-- Compare using String.Equals 00340090 0fb6f0 movzx esi,al 00340093 e83870f86c call mscorlib_ni+0x2570d0 (6d2c70d0) (System.Console.get_Out(), mdToken: 060008fd) 00340098 8bc8 mov ecx,eax 0034009a 8bd6 mov edx,esi 0034009c 8b01 mov eax,dword ptr [ecx] 0034009e 8b4038 mov eax,dword ptr [eax+38h] 003400a1 ff5010 call dword ptr [eax+10h] C:\dev\sandbox\cs-console\Program.cs @ 28: 003400a4 e87775596d call mscorlib_ni+0x867620 (6d8d7620) (System.Diagnostics.Debugger.Break(), mdToken: 0600239a) C:\dev\sandbox\cs-console\Program.cs @ 29: &gt;&gt;&gt; 003400a9 5e pop esi 003400aa 5d pop ebp 003400ab c3 ret </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload