Perhaps a small question but im curious.
What is favored?
In a controllers action, when passing arguments, when and how should they be used?
public ActionResult Action(bool aBool = false)
or
public ActionResult Action(bool? aNullableBool)
I tend to use defualt-value as its a bit more clear and eassier to check, but am i thinking wrong?
The two are not equivalent. In the first example, the caller must specify true
or false
, if he does not, false
is used.
In the second line, the caller may provide true
, or false
, or null
. You will need to decide how to handle null
. That's a third value that you can get. Plus the caller can not omit it. He needs to pass a value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With