Previous Topic Next topic Print topic


Enumeration - in COBOL and C#

Enumeration in Managed COBOL

enum-id Action public.
working-storage section. 
01 binary-long.         *> Underlying type for the enum. 
                        *> binary-long is the default
    78 Starter value 0. *> Declare enum values as level-78 items
    78 Stop    value 1.
    78 Rewind  value 2.
    78 Forward value 3.
end enum. 
*> Short hand version of above.
*> PUBLIC and BINARY-LONG are the defaults
*> The default values are 0 1 2...
enum-id Action.
   78 Starter.  
   78 Stop.
   78 Rewind.
   78 Forward.
end enum.
enum-id Status.
   78 Flunk value 50.
   78 Pass value 70.
   78 Excel value 90.
end enum.
program-id main.
   display type Status::Pass as binary-long *> prints 70
   display type Status::Pass                *> prints Pass
end program. 

Enumeration in C#

enum Action {Start, Stop, Rewind, Forward};
enum Status {Flunk = 50, Pass = 70, Excel = 90};
 
Action a = Action.Stop;
if (a != Action.Start)
  Console.WriteLine(a + " is " + (int) a);   // Prints "Stop is 1"
 
Console.WriteLine((int) Status.Pass);        // Prints 70
Console.WriteLine(Status.Pass);              // Prints Pass
Previous Topic Next topic Print topic