title: Execution order of conditions in C# If statement
body: <p>There are two if statements below that have multiple conditions using logical operators. Logically both are same but the order of check differs. The first one works and the second one fails.</p>
  
  <p>I referred <a href="http://msdn.microsoft.com/en-us/library/vstudio/5011f09h.aspx" rel="noreferrer">MSDN</a> for checking whether the order of execution of the conditions defined; but I could not find.</p>
  
  <p>Consider a multiple check condition that has <code>&amp;&amp;</code> as the logical operator. Is it guaranteed that it will always check the first condition and if that is not satisfied the second condition will <strong>not</strong> be checked?</p>
  
  <p>I used to use approach 1 and it works well. Looking for an MSDN reference substantiaing the use.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Refer <a href="https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/boolean-logical-operators#conditional-logical-or-operator-" rel="noreferrer">"short-circuit" evaluation</a></p>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>  List&lt;string&gt; employees = null;  
  
    if (employees != null &amp;&amp; employees.Count &gt; 0)
    {
          string theEmployee = employees[0];
    }
  
    if (employees.Count &gt; 0 &amp;&amp; employees != null)
    {
          string theEmployee = employees[0];
    }
  </code></pre>