IE 2060 Lecture : Lecture11 B Ch06 Functions Continued

25 views23 pages
15 Mar 2019
School
Course
Professor

Document Summary

There are cases where you may want some of the arguments to be optional; i. e. , the programmer does not need to provide them when calling the function. Parameters can be made optional by specifying a default value for them. There are two requirements for optional arguments: An optional argument must have a default value specified by following the argument name with an = sign and the default value. Optional arguments must appear at the end of the argument list. Example public void example1(int x, int y = 0) //code public void example2(datetime z = new datetime()) if (z == null) //code public void example3(int x, int y = 0, string z = "default") //will use default value of 0 for argument y. //will use default value of #1/1/2008# for argument z. Sometimes you may want a function to take a variable number of arguments.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents