zoukankan      html  css  js  c++  java
  • .net 实例化对象

    定义TestClass,在调用的地方

    TestClass a;

    如果下面有引用

    a.Property,VS会报错,而如果

    TestClass a = null;

    再次调用的话则不会报错。

    TestClass a; DebugIL代码:

    .method private hidebysig static void  Main(string[] args) cil managed
    {
      .entrypoint
      // Code size       2 (0x2)
      .maxstack  0
      .locals init ([0] class ConsoleApplication1.TestClass a)
      IL_0000:  nop
      IL_0001:  ret
    } // end of method Program::Main
    

    TestClass a = null; DebugIL代码:

    .method private hidebysig static void  Main(string[] args) cil managed
    {
      .entrypoint
      // Code size       4 (0x4)
      .maxstack  1
      .locals init ([0] class ConsoleApplication1.TestClass a)
      IL_0000:  nop
      IL_0001:  ldnull
      IL_0002:  stloc.0
      IL_0003:  ret
    } // end of method Program::Main
    

    TestClass a; Release IL代码,VS会优化掉该语句

    .method private hidebysig static void  Main(string[] args) cil managed
    {
      .entrypoint
      // Code size       1 (0x1)
      .maxstack  8
      IL_0000:  ret
    } // end of method Program::Main
    

    TestClass a = null; Release IL代码,VS同样会优化掉该句

    .method private hidebysig static void  Main(string[] args) cil managed
    {
      .entrypoint
      // Code size       1 (0x1)
      .maxstack  8
      IL_0000:  ret
    } // end of method Program::Main
    

    先Mark,以后在具体研究区别

  • 相关阅读:
    [USACO07DEC]观光奶牛Sightseeing Cows
    洛谷 U3348 A2-回文数
    LOJ #2037. 「SHOI2015」脑洞治疗仪
    1441 士兵的数字游戏
    BZOJ 1108: [POI2007]天然气管道Gaz
    P3047 [USACO12FEB]附近的牛Nearby Cows
    POJ 3061 Subsequence
    Hdu 5776 sum
    1052 最大M子段和
    1288 埃及分数
  • 原文地址:https://www.cnblogs.com/NailClipper/p/4643064.html
Copyright © 2011-2022 走看看