beginner · 24 minute study
Methods make input, output and responsibility visible
Extract a rule into a method you can call, test and reason about without duplicating it across screens.
Useful preparation · 1 prerequisite
Use this as a map, not a lock. If these ideas are familiar, continue.
- Guard invalid cases before repeating useful work — Most practical programs decide which inputs qualify and apply the same rule to each qualifying item. A misplaced condition can silently corrupt a summary.
First, build a mental model
A method is a small contract: give it these inputs, receive this output, and know which side effects it may perform. Its local names belong to that call.
- The signature states parameter types and return type. A void method has no return value for the caller to use.
- Normal parameters receive values. Reassigning a copied int parameter does not reassign the caller's variable.
- A return statement hands a result back and ends that path through the method.
- Prefer explicit inputs over hidden mutable globals. ref and out are explicit alternative parameter mechanisms, not the default.
static int AddBonus(int score, int bonus)
{
score += bonus;
return score;
}
int score = 10;
int preview = AddBonus(score, 2);
Console.WriteLine(score);
Console.WriteLine(preview);- Call
The method receives copies of 10 and 2.
- Local calculation
Its local score becomes 12 and is returned.
- Caller
preview receives 12, while the caller's score remains 10.
Production thinking
Take this beyond the example.
Give domain rules one home. Keep parsing, authorization and persistence visible around that rule so a reusable method does not become an accidental authority bypass.
Sources and further reading
Your evidence
unseen is a local learning signal, not a credential or proof of production competence.
Explain the mental model, then explicitly acknowledge it. Opening a page is not evidence.
Supported retries can complete this lesson. Independent evidence and delayed review determine the skill stage.
Next lesson · Copying a value and copying a reference are different →