i am using optional parameter in the following code. but that shows error "default parameter specifiers are not permitted" anybody help me sir.
public void getno(int pvalu, string pname = "")
{
}
It looks like there's some misinformation in some of the answers:
As others have stated, overloads are an alternative to using optional parameters if you're not using C# 4 or if you want your code to be consumed by earlier C# code. (If you build a library using C# 4 but then some C# 3 code needs to call into it, those optional parameters are effectively going to be required as far as that code is concerned.)
(As an aside, I would seriously reconsider your names... I know this is only sample code, but generally speaking prefixes like "p" for parameters are discouraged as a matter of convention, and likewise methods are generally Pascal-cased.)
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