title: Performance considerations of inheritance in C#
body: <p>Does the compiler produce the same IL if I make a class with <code>public int I;</code> (or any other field) vs making a class that inherits from a base class that has <code>public int I;</code>?</p>
  
  <p>Either way the resulting class behaves identically, but does the compiler behave identically?</p>
  
  <p>I.e., is the compiler just copy-pasting code from base classes into the derived classes, or is it actually creating two different class objects when you inherit?</p>
  
  <pre><code>class A
  {
      public int I;
  }
  
  class B : A
  {
  }
  </code></pre>
  
  <p>Now is there any performance difference between the following two DoSomething() calls?</p>
  
  <pre><code>var a = new A();
  var b = new B();
  DoSomething(a.I);
  DoSomething(b.I); // Is this line slower than the above line due to inheritance?
  </code></pre>
  
  <p>Try to ignore any optimizations the compiler might do for this special case. My question is about whether inheritance in C# in general has an associated performance penalty. Most of the time I don't care, but sometimes I want to optimize a piece of high frequency code.</p>