December 2001
Intermediate to advanced
416 pages
8h 16m
English
Often when we program we need to define a set of alternative attributes to associate with an object. A file, for example, might be open in one of three states: input, output, and append. One strategy to keep track of these state values is to associate a unique constant number with each one. Thus we might write
public class fileMode
{
public const int input = 1;
public const int output = 2;
public const int append = 3;
// ...
}
and use these constants as follows:
bool open_file( string file_name, int open_mode); // ... open_file( "Phoenix_and_the_Crane", fileMode.append );
The benefit is that it is much easier to use a set of mnemonic constant objects than to remember and make sense of the associated literal values. ...
Read now
Unlock full access