1.4.24 Arguments vs Parameters

Methods Can Receive Information

Until now, many method examples have used empty parentheses:

team1.DisplayName();

A method can also be designed to receive information when it is called.

That introduces two closely related terms:

  • parameter
  • argument

They describe different sides of the same method call.

A Parameter Appears in the Method Definition

Consider this method:

public void SetJerseyNumber(int number)
{
    this.jerseyNumber = number;
}

The parameter is:

int number

It appears in the method declaration.

The parameter tells C#:

An Argument Appears in the Method Call

Now consider:

player1.SetJerseyNumber(7);

The argument is:

7

It appears at the call site.

The argument is the actual value supplied to the method.

Connect the Two Sides

Method definition:

public void SetJerseyNumber(int number)

Method call:

player1.SetJerseyNumber(7);

The connection is:

Activity diagram showing argument 7, then parameter number.
Argument.
  • New
  • Changed
  • Removed

During that method call, number receives the value 7.

Read the Call in Plain Language

This statement:

player1.SetJerseyNumber(7);

can be read as:

Inside the method:

this.jerseyNumber = number;

can then be read as:

Parameter and Argument Are Not Interchangeable Terms

For technical explanations, keep the distinction clear.

Parameter

the named input declared by the method

Argument

the value supplied when the method is called
The Types Need to Be Compatible

If the method declares:

public void SetJerseyNumber(int number)

then the parameter expects an int-compatible argument.

This fits:

player1.SetJerseyNumber(7);

A text argument such as:

player1.SetJerseyNumber("seven");

does not match the parameter type.

The Parameter Name Is Used Inside the Method

Suppose:

public void SetJerseyNumber(int number)
{
    this.jerseyNumber = number;
}

The name:

number

is available inside this method body.

If the caller later uses:

player1.SetJerseyNumber(12);

then during that call:

number = 12

The method definition stays the same.

The incoming argument can change from call to call.

One Method Can Be Reused with Different Arguments

For example:

player1.SetJerseyNumber(7);
player2.SetJerseyNumber(12);

Both objects can use the same method design.

The calls supply different arguments.

Conceptually:

Activity diagram showing player1 call number receives 7, then player2 call number receives 12.
Player1CallNumberReceives.
  • New
  • Changed
  • Removed

That is one reason parameters make methods more reusable.

Keep the Current Scope to One Parameter

Later Learning Activities introduce methods with multiple parameters.

For now, focus on the basic relationship:

Activity diagram showing one argument, then one parameter, then method behavior.
OneArgument.
  • New
  • Changed
  • Removed