Back to course

Method Parameters and Arguments

C# Zero to Hero: Comprehensive Programming Masterclass

Passing Data to Methods

Parameters act as variables inside the method.

Example

csharp static void GreetUser(string name, int age) { Console.WriteLine($"Hello {name}, you are {age} years old."); }

static void Main(string[] args) { GreetUser("Alice", 30); }

Default Parameters

You can use the = sign to provide a default value: csharp static void MyCountry(string country = "Norway") { ... }