params, ref and out
params takes any number of arguments, ref passes by reference and out returns extra values.
Example
static int Sum(params int[] n) => n.Sum();
static void Twice(ref int x) { x *= 2; }
static bool TryHalf(int n, out int half) { half = n / 2; return n % 2 == 0; }
int v = 5; Twice(ref v);
Console.WriteLine($"{Sum(1, 2, 3)} {v} {TryHalf(8, out var h)} {h}");Exercise
Any number of args.
static int F( int[] n)
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.