title: Conditional expression cannot be determined error with ternary operator
body: <p>The following error comes with <code>ternary operator</code>.</p>
  
  <blockquote>
    <p>Error: Type of conditional expression cannot be determined because there is no implicit conversion between '' and 'int'</p>
  </blockquote>
  
  <p>Why is this error appearing even though I have specified <code>(int)(result)</code> for the <code>ExecuteScalar</code> result? How can we correct it?</p>
  
  <p><strong>CODE</strong></p>
  
  <pre><code>    public int? GetWINFromAssociateID(int associateID)
      {
          int? WIN =null;
          using (SqlConnection connection = new SqlConnection(connectionString))
          {
              connection.Open();
              string commandText = DataLayerConstants.GetWINFromAssociateIDCommand;
              using (SqlCommand command = new SqlCommand(commandText, connection))
              {
                  command.CommandType = System.Data.CommandType.Text;
                  command.Parameters.AddWithValue("@payroll_svc_assoc_id", associateID);
  
                  var result = command.ExecuteScalar();
                  WIN = result == DBNull.Value ? null : (int)(result);
              }
          }
          return WIN;
      }
  </code></pre>
  
  <p><strong>UPDATED REFERENCES</strong></p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/2215745/conditional-operator-cannot-cast-implicitly/2215959#2215959">Conditional operator cannot cast implicitly?</a></li>
  <li><a href="http://blogs.msdn.com/b/ericlippert/archive/2006/05/24/type-inference-woes-part-one.aspx" rel="nofollow noreferrer">Type inference woes, part one - by Eric Lippert</a></li>
  </ol>