title: If Condition of VB.NET (IIf) is not equal by C# (?:)
body: <p>The <a href="https://msdn.microsoft.com/en-us/library/27ydhh0d(v=vs.71).aspx" rel="nofollow">IIf function</a> in VB.NET :</p>
  
  <pre><code>IIf(condition As Boolean, TruePart As Object, FalsePart As Object) As Object
  </code></pre>
  
  <p>exactly is not equal by C# <a href="https://msdn.microsoft.com/en-us/library/ty67wk28.aspx" rel="nofollow">conditional operator (?:)</a> :</p>
  
  <pre><code>condition ? first_expression : second_expression;
  </code></pre>
  
  <p>When I convert some codes from c# to vb.net, I understand that converted codes not work correctly because in vb.net if conditional are evaluated both of the true and false parts before the condition is checked!</p>
  
  <p>For example, C#:</p>
  
  <pre><code>public int Divide(int number, int divisor)
  {
      var result = (divisor == 0) 
                   ? AlertDivideByZeroException() 
                   : number / divisor;
  
      return result;
  }
  </code></pre>
  
  <p>VB.NET:</p>
  
  <pre class="lang-vb prettyprint-override"><code>Public Function Divide(number As Int32, divisor As Int32) As Int32
  
       Dim result = IIf(divisor = 0, _
                    AlertDivideByZeroException(), _
                    number / divisor)
  
       Return result
  
  End Function
  </code></pre>
  
  <p>Now, my c# codes executed successfully but vb.net codes every times that <code>divisor</code> is not equal by zero, runs both of <code>AlertDivideByZeroException()</code> and <code>number / divisor</code>.</p>
  
  <p><strong>Why this happens ?</strong></p>
  
  <p>and </p>
  
  <p><strong>How and with what do I replace the c# if-conditional operator (?:) in VB.net ?</strong></p>