O'Reilly logo

Visual C#® 2012: How to Program, Fifth Edition by Harvey Deitel, Paul Deitel

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7.14. Named Parameters

Normally, when calling a method that has optional parameters, the argument values—in order—are assigned to the parameters from left to right in the parameter list. Consider a Time class that stores the time of day in 24-hour clock format as int values representing the hour (0–23), minute (0–59) and second (0–59). Such a class might provide a SetTime method with optional parameters like

public void SetTime( int hour = 0, int minute = 0, int second = 0 )

In the preceding method header, all three of SetTime’s parameters are optional. Assuming that we have a Time object named t, we can call SetTime as follows:

t.SetTime(); // sets the time to 12:00:00 AM t.SetTime( 12 ); // sets the time to 12:00:00 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required