Default values
C# supports default values for parameters and so does this library.
Let's make some changes to Calculator to add a new Command - Divide
. And let's default value2 to 1 when user doesn't provide a value.
This will prevent the calculator from crashing because of DivideByZeroException
public void Divide(int value1, int value2 = 1)
{
Console.WriteLine($"Answer: {value1 / value2}");
}
Here's how help looks like:
INPUT
dotnet example.dll Divide --help
OUTPUT
Usage: dotnet example.dll Divide [arguments] [options]
Arguments:
value1 Int32
value2 Int32 | Default value: 1
Options:
-h | -? | --help Show help information