LLearnCode
Academy/csharp/Read and write small programs

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.

Loading progressEvidence grows with practice
Useful preparation · 1 prerequisite

Use this as a map, not a lock. If these ideas are familiar, continue.

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.

  1. The signature states parameter types and return type. A void method has no return value for the caller to use.
  2. Normal parameters receive values. Reassigning a copied int parameter does not reassign the caller's variable.
  3. A return statement hands a result back and ends that path through the method.
  4. Prefer explicit inputs over hidden mutable globals. ref and out are explicit alternative parameter mechanisms, not the default.
Read the codecsharp · educational example
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);
  1. Call

    The method receives copies of 10 and 2.

  2. Local calculation

    Its local score becomes 12 and is returned.

  3. 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 →