mercredi 7 janvier 2015

"Cannot be determined because there is no implicit conversion" with ternery if return

I have the following ASP.NET Web Api 2 action with a ternery 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 ternery if, the compiler is happy:



if (deleted)
{
return this.Ok();
}
return this.NotFound();


Why is this?


Aucun commentaire:

Enregistrer un commentaire