×

c# · level 1 · unit 7 · lesson 2

  1. meet it
  2. guess first
  3. your turn
  4. fix it
  5. nailed it

Tap a green word if you get lost.

meet it

A is a slot where your function catches information.

Picture your function as a machine. Right now it does the same thing every time. Cut a slot in the front, and you can feed in something new on each go.

That slot is a parameter: a box in the function's brackets, with a type and a name, like string name in void Greet(string name). Inside the function, use it like any other box.

The value you drop in when you call is the . Call Greet("Mia") and name holds "Mia". Call Greet("Leo") and the same machine greets Leo instead.

using System;

Greet("Mia");
Greet("Leo");

void Greet(string name)
{
    Console.WriteLine($"Hello, {name}!");
}

Need two slots? Separate the parameters with commas, and the arguments too.