c# - do all local variables go on the stack -


What is the memory overhead on the heap and heap of A versus B

A:

< Pre> Private string test A () {string a = _builder.Build (); Return; }

b:

  private string test (b) {returns _bilder. Build (); }  

Again the efficiency question; Both are identical, and in release mode the same thing will be reduced to some extent, string is a reference type, hence the string is always on the stack on the stack The only thing string - will reference some bytes (no fixed length of the length).

"Go to all local steps stack": no;

  • Iterator block ( yield returns etc.)
  • UL>

    In both cases, there is a compiler generated square behind the complexes:

      int i = 1; Action action = delegate {i ++;}; Action (); Console.WriteLine (i);  

    is the same:

      square fu {public int i; // Yes, a public sector public void some method () {i ++;}} ... fu fu = new fu (); Foo.i = 1; Action action = foo.SomeMethod; Action (); Console.WriteLine (foo.i);  

    Therefore i is on an object, so on the heap.

    Iterator blocks work the same way, but with the state machine.


    Comments