Should you declare methods using overloads or optional parameters in C# 4.0?

I’d consider the following:

  • Do you need your code to be used from languages which don’t support optional parameters? If so, consider including the overloads.
  • Do you have any members on your team who violently oppose optional parameters? (Sometimes it’s easier to live with a decision you don’t like than to argue the case.)
  • Are you confident that your defaults won’t change between builds of your code, or if they might, will your callers be okay with that?

I haven’t checked how the defaults are going to work, but I’d assume that the default values will be baked into the calling code, much the same as references to const fields. That’s usually okay – changes to a default value are pretty significant anyway – but those are the things to consider.

Leave a Comment