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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top