title: Why don't small changes in code affect exe file size?
body: <p>I'm curious - sometimes I make changes in my code, recompile, then copy my exe or dll file over the old version and see Windows telling me that the date of the file changed, but the size stayed exactly the same. Why is that?</p>
  
  <p>As an example, I tested with the following console application:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace ConsoleApplication4
  {
      class Program
      {
          static void Main(string[] args)
          {
              int a = 1;
              int b = 2;
              Console.WriteLine(a + b);
          }
      }
  }
  </code></pre>
  
  <p>This produced an exe file of 5120 bytes (Visual Studio 2012, Debug build). Then, I changed the code to this:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  
  namespace ConsoleApplication4
  {
      class Program
      {
          static void Main(string[] args)
          {
              int a = 1;
              int b = 2;
              int c = 3;
              Console.WriteLine(a + b + c);
          }
      }
  }
  </code></pre>
  
  <p>The size of the exe is exactly the same.</p>
  
  <p>I look at the disassembly, which is showing a difference in the IL code, so it cannot be that the difference is optimized away:</p>
  
  <p>First version:</p>
  
  <pre><code>.method private hidebysig static void  Main(string[] args) cil managed
  {
    .entrypoint
    // Code size       15 (0xf)
    .maxstack  2
    .locals init (int32 V_0,
             int32 V_1)
    IL_0000:  nop
    IL_0001:  ldc.i4.1
    IL_0002:  stloc.0
    IL_0003:  ldc.i4.2
    IL_0004:  stloc.1
    IL_0005:  ldloc.0
    IL_0006:  ldloc.1
    IL_0007:  add
    IL_0008:  call       void [mscorlib]System.Console::WriteLine(int32)
    IL_000d:  nop
    IL_000e:  ret
  } // end of method Program::Main
  </code></pre>
  
  <p>Second version:</p>
  
  <pre><code>.method private hidebysig static void  Main(string[] args) cil managed
  {
    .entrypoint
    // Code size       19 (0x13)
    .maxstack  2
    .locals init ([0] int32 a,
             [1] int32 b,
             [2] int32 c)
    IL_0000:  nop
    IL_0001:  ldc.i4.1
    IL_0002:  stloc.0
    IL_0003:  ldc.i4.2
    IL_0004:  stloc.1
    IL_0005:  ldc.i4.3
    IL_0006:  stloc.2
    IL_0007:  ldloc.0
    IL_0008:  ldloc.1
    IL_0009:  add
    IL_000a:  ldloc.2
    IL_000b:  add
    IL_000c:  call       void [mscorlib]System.Console::WriteLine(int32)
    IL_0011:  nop
    IL_0012:  ret
  } // end of method Program::Main
  </code></pre>
  
  <p>If the code is physically bigger, how can the files be exactly the same size? Is this just some random chance? It happens to me a lot (when making small changes to the code)...</p>