...

/

Function Basics: Parameter, Arguments, and Returning Values

Function Basics: Parameter, Arguments, and Returning Values

Learn about the difference between parameters and arguments in functions and explore writing a function that returns a value by creating a tax calculation application in C#.

Most developers will use the terms argument and parameter interchangeably in daily usage. Strictly speaking, the two terms have specific and subtly different meanings. But just like a person can be both a parent and a doctor, the terms often apply to the same thing.

Parameter and arguments

parameter is a variable in a function definition. For example, startDate is a parameter of the Hire function, as shown in the following code:

Press + to interact
void Hire(DateTime startDate)
{
// implementation
}

When a method is called, an argument is the data we pass into the method’s parameters. For example, when is a variable passed as an argument to the Hire function, as shown in the following code:

Press + to interact
DateTime when = new(year: 2022, month: 11, day: 8);
Hire(when);

Example

We might prefer to specify the parameter name when passing the argument, as shown in the following code:

Press + to interact
DateTime when = new(year: 2022, month: 11, day: 8);
Hire(startDate: when);

When talking about the call to the Hire function, startDate is the parameter, and when is the argument.

Note: The official Microsoft documentation uses the phrases “named and optional arguments” and “named and optional parameters” interchangeably. We can read more about it. ...