title: Ternary operator in Linq
body: <pre><code>var result = from payroll in currentMonthPayroll
      select new SalaryDifference
      {
          PreviousMonthSalary = previousMonthPayroll.Where(t =&gt; t.EmployeeId == payroll.EmployeeId).FirstOrDefault() == null ?
          default(decimal) : previousMonthPayroll.Where(t =&gt; t.EmployeeId == payroll.EmployeeId).FirstOrDefault().Salary,
      };
  </code></pre>
  <p>Is there a way not to repeat the <code>previousMonthPayroll.Where(t =&gt; t.EmployeeId == payroll.EmployeeId).FirstOrDefault()</code> logic to pick <code>Salary</code> value?</p>
  <p>I tried:</p>
  <pre><code>previousMonthPayroll.Where(t =&gt; t.EmployeeId == payroll.EmployeeId)
      .FirstOrDefault().Salary ?? default(decimal);
  </code></pre>
  <p>But, if <code>previousMonthPayroll.Where(t =&gt; t.EmployeeId == payroll.EmployeeId).FirstOrDefault()</code> is null, it throws exception.</p>