I have a method which accepts three optional parameters.
public int DoStuff(int? count = null, bool? isValid = null, string name = "default")
{
//Do Something
}
My question is, if I call this method and pass a single method argument:
var isValid = true;
DoStuff(isValid);
I get the the following error:
Argument 1: cannot convert from 'bool' to 'int?'
Is it possible to pass a single method argument, and specify which parameter I wish to specify?
Since the first parameter is count
, it is expecting an int?
not a bool
.
You can provide named parameters like it describes here.
DoStuff(isValid: true);
Yes, it is possible.
DoStuff(isValid: true);
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