title: Conditional operator assignment with Nullable<value> types?
body: <pre><code>EmployeeNumber =
  string.IsNullOrEmpty(employeeNumberTextBox.Text)
      ? null
      : Convert.ToInt32(employeeNumberTextBox.Text),
  </code></pre>
  <p>I often find myself wanting to do things like this (<code>EmployeeNumber</code> is a <code>Nullable&lt;int&gt;</code> as it's a property on a LINQ-to-SQL dbml object where the column allows NULL values).  Unfortunately, the compiler feels that</p>
  <blockquote>
  <p>There is no implicit conversion between 'null' and 'int'</p>
  </blockquote>
  <p>even though both types would be valid in an assignment operation to a nullable int on their own.</p>
  <p>Using the null coalescing operator is not an option as far as I can see because of the inline conversion that needs to happen on the <code>.Text</code> string if it's not null.</p>
  <p>As far as I know the only way to do this is to use an if statement and/or assign it in two steps.  In this particular case I find that very frustrating because I wanted to use the object initializer syntax and this assignment would be in the initialization block...</p>
  <p>Does anyone know a more elegant solution?</p>