An optional parameter is a parameter that you can either include or omit when invoking the method. To specify that a parameter is optional, you need to include a default value for that parameter in the method declaration. The syntax for specifying the default value is the same as that of initializing a local variable. All required parameters must be declared before any optional parameters are declared. If there is a params parameter, it must be declared after all the optional parameters.
2 | namespace OptionalParamter |
6 | static void Main( string [] args) |
8 | MyClass mc = new MyClass(); |
11 | Console.WriteLine($ "{ r0 }, { r1 }" ); |
16 | public int Calc( int a = 7) |
You can mix them.
1 | public int Calc( int x, int a = 7) |