Now let's imagine that we need to display different messages in response to a user error, depending on whether exactly what mistake he made.
In this case, you can write your own procedure for each error:
void printErrorZero()
{
Console.WriteLine("Error. Division by zero!");
}
void printErrorInput()
{
Console.WriteLine("Error in input!");
}
What if there are many more possible errors? Then this solution will not suit us.
We need to learn how to control the procedure by telling it what error message to display.
To do this, we need parameters that we will write in parentheses after the procedure name
void printError(string s)
{
Console.WriteLine(s);
}
In this procedure, s is a parameter - a special variable that allows control the procedure.
The parameter is a variable whose value the operation of the subroutine depends on. Parameter names are listed separated by commas in the subprogram header. The parameter type is written before the parameter.
Now, when calling the procedure, you need to specify the actual value in parentheses that will be assigned to the parameter (the variable s) inside our procedure
printError("Error! Division by zero!");
This value is called an argument.
The argument is the parameter value that is passed to the subroutine when it is called.
The argument can be not only a constant value, but also a variable or an arithmetic expression.< /span>