A method can declare one or more parameters:
public void SetJerseyNumber(int number)
{
this.jerseyNumber = number;
}The parameter:
numberis ready to receive a value when the method is called.
A call supplies that value as an argument:
player1.SetJerseyNumber(7);The argument:
7is passed into the parameter:
numberA useful mental model is:
For:
player1.SetJerseyNumber(7);and:
public void SetJerseyNumber(int number)
{
this.jerseyNumber = number;
}the flow is:
The caller supplies the value.
The method receives it through the parameter.
The method can then use the parameter in its own logic.
Suppose:
public void SetPlayerInfo(string name, int number)
{
this.name = name;
this.jerseyNumber = number;
}A matching call is:
player1.SetPlayerInfo("Jordan", 7);The arguments match the parameters by position:
The first argument is used for the first parameter.
The second argument is used for the second parameter.
If the method expects:
int numberthen this call is compatible:
player1.SetJerseyNumber(7);This call is not:
player1.SetJerseyNumber("seven");The argument must be compatible with the parameter type.
The same rule applies when parameters use:
string
bool
doublebool
doubleor another available type.
A literal is a value written directly in the call.
Examples:
player1.SetJerseyNumber(7);
player1.SetAvailability(true);
player1.SetPosition("Forward");The literals are:
7
true
"Forward"Each one becomes the value of the matching parameter during the call.
Suppose a method already has:
int selectedNumber = 9;The local variable can be used as an argument:
player1.SetJerseyNumber(selectedNumber);The current value stored in:
selectedNumberis supplied to the method parameter.
Conceptually:
If:
team1.defaultJerseyNumberis an int, it can be used where an int argument is expected:
player1.SetJerseyNumber(team1.defaultJerseyNumber);The argument expression reads the current field value.
The method receives that value through its parameter.
Consider:
int selectedNumber = 9;
player1.SetJerseyNumber(selectedNumber);Inside:
public void SetJerseyNumber(int number)
{
this.jerseyNumber = number;
}the parameter is named:
numberThe caller's local variable is named:
selectedNumberThe names do not have to match.
The value is what moves across the method-call boundary.
Suppose:
int selectedNumber = 9;
player1.SetJerseyNumber(selectedNumber);The method receives the value through its parameter.
Changing the Player field does not automatically change:
selectedNumberThe local variable and the object field are different storage locations.
A method can receive a value through a parameter and then use that parameter as the argument in another method call.
This is called forwarding an argument.
Conceptually:
The same information can move through more than one method call.
Suppose Team has:
public void DisplayMessage(string message)
{
System.Console.WriteLine(message);
}Player has a Team reference:
public Team team;Player can define:
public void SendTeamMessage(string message)
{
this.team.DisplayMessage(message);
}The Player method receives message.
Then it passes that value to the Team method.
Suppose:
player1.SendTeamMessage("Practice starts at 5.");The first call supplies:
"Practice starts at 5."to the Player parameter:
messageInside SendTeamMessage, the code calls:
this.team.DisplayMessage(message);The current value of message becomes the argument for DisplayMessage.
The information flow is:
The Player method does not need to create a new text value. It can forward the value it already received.
Inside:
public void SendTeamMessage(string message)message is a parameter.
Inside this call:
this.team.DisplayMessage(message);that same expression is being used as the argument supplied to another method.
The role depends on which side of the method-call boundary you are looking at.
In:
this.team.DisplayMessage(message);there are two important pieces.
this.teamWhich object receives the call?
messageWhich value is sent to the receiving method?
Tracing both makes object-to-object method calls easier to follow.
Suppose:
public void SendTeamMessage(string message)
{
this.team.DisplayMessage(message);
}The Player receives the text and passes it onward.
The Player does not automatically keep that text as object state.
If the class needs to remember the value later, the design would need a field assignment that explicitly stores it.
Parameters and fields remain different.
In the example:
the value moves from the caller into Player behavior and then into Team behavior.
This connects parameters with the object-to-object method calls you learned earlier.
A specific call can be represented conceptually in a sequence diagram as:
controller1 ── SetJerseyNumber(7) ──> player1A forwarded call can also show the value continuing to another object:
A class diagram can show the method parameter:
SetJerseyNumber(number : int) : voidC# connects those representations through the actual method calls.
When debugging a parameterized method:
That turns method calls into traceable value flow rather than mysterious jumps between source files.
Later modules introduce methods that return values and allow a returned value to become another argument.
That is not needed here.
For now, forward a value that the current method already received as a parameter.
Keep this relationship clear: