Setting default method parameters

  • Thread starter Thread starter Mark F.
  • Start date Start date
M

Mark F.

In VC++ you can preassign a default value to an argument passed to a
function.

CString GetLastName(BOOL bUpper = TRUE, CString sName)
{
// if the flag is omitted the return string is upper case by default.
}

Can you do the same thing in C# methods?

Thanks,
Mark
 
No, you cannot. You would have to write separate overloads of the method
with different parameters, and have one overload call the other with the
default value being passed into the call.
 
Marina Levit said:
No, you cannot. You would have to write separate overloads of the method
with different parameters, and have one overload call the other with the
default value being passed into the call.

Too bad, it's a very useful coding shortcut when designing custom methods.

Mark
 
Back
Top