Previous Topic Next topic Print topic


Enumeration - in COBOL and C# and VB.NET

C# COBOL VB.NET
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
enum-id Action.
   78 #Start.   *> Start is a reserved word so use '#' symbol
   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.

class-id MainClass.
method-id main static.
   declare a = type Action::Stop
   if a not = type Action::Start
       display a & " is " & a as binary-long   *> Prints "Stop is 1"
    end-if
   display type Status::Pass as binary-long    *> prints 70
   display type Status::Pass *> prints 
end method.
end class.
Enum Action
  Start
  [Stop]   ' Stop is a reserved word
  Rewind
  Forward
End Enum

Enum Status
  Flunk = 50
  Pass = 70
  Excel = 90
End Enum

Dim a As Action = Action.Stop
If a <> Action.Start Then _
   Console.WriteLine(a.ToString & " is " & a)     ' Prints "Stop is 1"

Console.WriteLine(Status.Pass)                    ' Prints 70
Console.WriteLine(Status.Pass.ToString())         ' Prints Pass
Previous Topic Next topic Print topic