title: Optimized logic in an if....else condition
body: <p>Does anybody have an optimized logic for following if...else condition.....
  <br/><b>Scenario</b><br/></p>
  
  <ol>
  <li>Three date parameters are there: DateFrom, DateUntil and NewDateUntil. </li>
  <li><code>If DateFrom &lt;= DateNewUntil And DateUntil &gt; NewDateUntil then</code> add a warning message and returns true</li>
  <li><code>If DateFrom &gt; DateNewUntil And DateUntil &gt; DateNewUntil then</code> add a warning message and returns false</li>
  <li><code>If DateUntil &lt; DateNewUntil</code> then just <code>returns true</code>.
  <br/> Original code is commented below. Tried some optimization.<br/> Please have a look.</li>
  </ol>
  
  <p><b>Code</b></p>
  
  <pre><code>public bool ValidateDate(DateTime pDateFrom, DateTime pDateUntil, DateTime pNewDateUntil)
  {
    ////Original Code
    //if ((pDateUntil.Date &gt; pNewDateUntil.Date))
    //{
    //  if ((pDateFrom.Date &lt;= pNewDateUntil.Date))
    //  {
    //    pDateUntil = pNewDateUntil;
    //    AddWarningMessage("Warning Message");
    //    return true;
    //  }
    //  else if ((pDateFrom.Date &gt; pNewDateUntil.Date))
    //  {
    //    AddWarningMessage("Warning Message");
    //    return false;
    //  }
    //}
    //else
    //{
    //  return true;
    //}
  
    //Optimized As:
    bool returnValue = false;
    if ((pDateUntil &gt; pNewDateUntil.Date))
    {
      returnValue = pDateFrom &lt;= pNewDateUntil.Date ? true : false;
      AddWarningMessage("Warning Message");
    }
    else
    {
      returnValue = true;
    }
    return returnValue;
  }
  </code></pre>