Parameters
In this page:
Parameters
Parameters let a method receive input values from its caller, each with a declared type and name. Arguments are passed by value for value types by default, meaning the method gets its own copy. Multiple parameters are separated by commas in both the declaration and the call.
Note: Parameter names should describe their purpose, not just their type.
Example: Parameters
using System;
class Program
{
static void Greet(string name, int times)
{
for (int i = 0; i < times; i++)
{
Console.WriteLine($"Hello, {name}!");
}
}
static void Main(string[] args)
{
Greet("Sam", 3);
}
}
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 6 topics to unlock
0/6 topics done
Complete these topics first: