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

1
2
3
4
public void Divide(int value1, int value2 = 1)
{
    Console.WriteLine($"Answer: {value1 / value2}");
}

Here's how help looks like:

INPUT

1
dotnet example.dll Divide --help 

OUTPUT

1
2
3
4
5
6
7
8
Usage: dotnet example.dll Divide [arguments] [options]

Arguments:
  value1  Int32
  value2  Int32 | Default value: 1

Options:
  -h | -? | --help  Show help information

Last update: February 22, 2020