I would like to do something like below:
private void MyMethod(int param1, int param2 = param1){}
The intent is to make param2 optional, and where it is not specified, give it the same value as the first parameter.
Is this possible?
I am aware that I can use nullable types and do the check and assignment in the method body. I also know I could achieve this through overloading. I specifically want to know if this is possible in the signature.
I'm using .Net 4.0
Thanks
Is this possible?
No. Default values for parameters have to be one of:
default(Foo) or default (as of C# 7.1)new Guid()It's quite restrictive, unfortunately.
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