Last post Apr 08, 2020 07:27 AM by Rena Ni
Apr 07, 2020 10:40 PM|InspiredJide|LINK
Ok so normally I write my apis like this
public IEnumerable<WeatherForecast> Get()
but of recent I saw a couple of my .net friends use the ActionResult. Some thing like this below
public ActionResult<IEnumerable<WeatherForecast>> Get()
Ok so is it a better coding practice to use ActionResult. Please enlighten me. I dont use this till now and my api works fine. But I am very curious on best coding practice.
Cos I know on the international level this is what makes a developer stand out from the baby programmers.
Apr 08, 2020 07:27 AM|Rena Ni|LINK
ActionResult enables you to return a type deriving from ActionResult or return a specific
Most actions have a specific return type. Unexpected conditions can occur during action execution, in which case the specific type isn't returned. For example, an action's input parameter may fail model validation. In such a case, it's common to return
the appropriate ActionResult type instead of the specific type.
More details you could refer to: