What is faster in C#, an if statement, or a virtual function call to a function that does nothing? And why? : <p>Say you have a class called <code>MyClass</code> which has a certain behavior encapsulated using a reference (<code>myBehavior</code>) to another class called <code>Behavior</code>.  By default <code>MyClass</code> should have no behavior.</p>

<p>For instances which hadn't set <code>myBehavior</code> to anything after it was initialized   -  Would it be more speed efficient if <code>myBehavior</code> was initialized to <code>null</code>, and each time it was needed checked with <code>if(myBehavior)</code> or would it be faster if it were initialized to an instance of a <code>NullBehavior</code>, derived from <code>Behavior</code>, which does nothing?  and why?</p>

<pre><code>class MyClass
{
   Behavior myBehavior = null;

   void doSomething()
   {
      if(myBehavior)
      {
         myBehavior.performAction();
      }
   }
}
</code></pre>

<p>or:</p>

<pre><code>class NullBehavior : Behavior
{
   override void performAction()
   {
      // don't do anything
   }
}

class MyClass
{
   Behavior myBehavior = new NullBehavior(); // or equals some static universal instance of NullBehavior

   void doSomething()
   {
      myBehavior.performAction();
   }
}
</code></pre>
