0
Not understanding how default parameter values work
static int Pow(int x, int y=2) { int result = 1; for (int i = 0; i < y; i++) { result *= x; } return result; } static void Main(string[] args) { Console.WriteLine(Pow(6)); //Outputs 36 Console.WriteLine(Pow(3, 4)); //Outputs 81 } is the Pow method defaulting to multiplying itself by the argument value here? Cannot get my head around this! Any help is appreciated.
1 Odpowiedź
+ 3
If you didn't pass the second parameter it will have default value (here it is 2)
If you passed, then your second parameter will be as you defined it