I have the following ASP.NET Web Api 2 action with a ternary if return:
[HttpDelete]
public IHttpActionResult Delete()
{
bool deleted;
// ...
return deleted ? this.Ok() : this.NotFound();
}
I receive a
Type of conditional expression cannot be determined because there is no implicit conversion between 'System.Web.Http.Results.OkResult' and 'System.Web.Http.Results.NotFoundResult'
when they both implement IHttpActionResult
.
However if I remove the ternary if, the compiler is happy:
if (deleted)
{
return this.Ok();
}
return this.NotFound();
Why is this?