title: Check if null before set to null?
body: <p>Should we check if variable is null before setting it to null?</p>
  
  <pre><code>if (MyBills != null) 
  {
      MyBills = null;
  }
  </code></pre>
  
  <p>For, example, in a <a href="https://stackoverflow.com/questions/583454/check-if-variable-null-before-assign-to-null">Java related question</a> the performance implications are minimal. 
  Is this the case in C#? Other implications?</p>
  
  <h2>Testing</h2>
  
  <p>I've created the following code to test:</p>
  
  <pre><code>var watch = System.Diagnostics.Stopwatch.StartNew();
  
  int iterations = int.MaxValue;
  List&lt;int&gt; myBills= null;
  for (var i = 0; i &lt; iterations; i++)
  {
      if (myBills!= null)
      {
          myBills = null;
      }
  }
  watch.Stop();
  var elapsedMs = watch.ElapsedMilliseconds;
  Console.WriteLine(elapsedMs);
  </code></pre>
  
  <p>Running it on <a href="http://rextester.com/" rel="nofollow noreferrer">rextester</a> with and without the <code>if (myList != null)</code> the results are as following:</p>
  
  <pre><code>With check      Without check
  988             941
  938             1021
  953             987
  998             973
  1004            1031
  
  Average 
  976.2           990.6
  </code></pre>
  
  <p>So, even testing it in a non-controlled environment, the performance implications are irrelevant.</p>