C# – Is overloading the only way to have default function arguments in C#

c++, overloading

Is it true that the only way to handle default function arguments is through function overloading?

For example, in PHP I can do this:

function foo($x, $y=0){}

Would the best way to handle it in C# be this?

void foo(int x){  foo(x, 0);}void foo(int x, int y){}

Example lifted from here


Made the C# example into actual C# (Thanks Blair Conrad)

Best Solution

Yes, that'd be best, except you'd omit the $s on the parameter names, as others have pointed out. For those interested in the rationale behind the lack of default parameter values, see @Giovanni Galbo's explanation.