Skip to content
Justice Tech School

C# Parameters

Parameters can have default values, be passed by name, and use ref or out to change the caller variable. params accepts any number of arguments.

Example
static int Sum(params int[] n) => n.Sum();
static string Hi(string name = "friend", string end = "!") => "Hello " + name + end;
Console.WriteLine(Sum(1, 2, 3, 4));
Console.WriteLine(Hi(end: "?"));
static void Twice(ref int x) { x *= 2; }
int v = 5; Twice(ref v); Console.WriteLine(v);

Exercise

Accept many arguments.

static int F( int[] n)

Quiz Test

What does ref do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.