zoukankan      html  css  js  c++  java
  • equal 与 ==

                var s1 = new { Name = "abc" };
                var s2 = new { Name = "abc" };
    
                Debug.WriteLine(s1.Equals(s2));
                Debug.WriteLine(s1 == s2);
    
                var s3 = s2;
                Debug.WriteLine(s2.Equals(s3));
                Debug.WriteLine(s2 == s3);
    
     .entrypoint
      // 代码大小       92 (0x5c)
      .maxstack  2
      .locals init ([0] class '<>f__AnonymousType0`1'<string> s1,
               [1] class '<>f__AnonymousType0`1'<string> s2,
               [2] class '<>f__AnonymousType0`1'<string> s3)
      IL_0000:  nop
      IL_0001:  ldstr      "abc"
      IL_0006:  newobj     instance void class '<>f__AnonymousType0`1'<string>::.ctor(!0)
      IL_000b:  stloc.0
      IL_000c:  ldstr      "abc"
      IL_0011:  newobj     instance void class '<>f__AnonymousType0`1'<string>::.ctor(!0)
      IL_0016:  stloc.1
      IL_0017:  ldloc.0
      IL_0018:  ldloc.1
      IL_0019:  callvirt   instance bool [mscorlib]System.Object::Equals(object)
      IL_001e:  box        [mscorlib]System.Boolean
      IL_0023:  call       void [System]System.Diagnostics.Debug::WriteLine(object)
      IL_0028:  nop
      IL_0029:  ldloc.0
      IL_002a:  ldloc.1
      IL_002b:  ceq
      IL_002d:  box        [mscorlib]System.Boolean
      IL_0032:  call       void [System]System.Diagnostics.Debug::WriteLine(object)
      IL_0037:  nop
      IL_0038:  ldloc.1
      IL_0039:  stloc.2
      IL_003a:  ldloc.1
      IL_003b:  ldloc.2
      IL_003c:  callvirt   instance bool [mscorlib]System.Object::Equals(object)
      IL_0041:  box        [mscorlib]System.Boolean
      IL_0046:  call       void [System]System.Diagnostics.Debug::WriteLine(object)
      IL_004b:  nop
      IL_004c:  ldloc.1
      IL_004d:  ldloc.2
      IL_004e:  ceq
      IL_0050:  box        [mscorlib]System.Boolean
      IL_0055:  call       void [System]System.Diagnostics.Debug::WriteLine(object)
      IL_005a:  nop
      IL_005b:  ret
    
    结果是……
  • 相关阅读:
    mysql主从之双主配置
    mysql主从之binlog的工作模式
    mysql主从之主机名导致主从机制失败的问题
    python_文件 处理
    python_字典 学习
    python_元组 学习
    python 基础内置函数表及简单介绍
    python 列表学习
    python函数基础学习
    python迭代器、生成器、列表推倒式
  • 原文地址:https://www.cnblogs.com/donhwa/p/2002713.html
Copyright © 2011-2022 走看看