Home > Articles > Software Development & Management > Object Technology

  • Print
  • + Share This
This chapter is from the book

Default and Optional Parameters

Optional parameters are really just shortcuts to overloading methods. There are two ways to indicate that a parameter is optional. The obvious way is to use the Optional keyword, like so:

aMethod(aString as String, Optional anInteger as Integer)

The second way is to establish a default value for one of the parameters. Another way to accomplish what I just did in the previous example is this:

aMethod(aString as String, anInteger as Integer = 100)

Really, the Optional keyword just sets a default value of "0" to the anInteger variable, so the only real difference is that you get to set an arbitrary default value when using the second approach.

  • + Share This
  • 🔖 Save To Your Account