Enum type def

  • Thread starter Thread starter MuZZy
  • Start date Start date
M

MuZZy

Hello,
I want to define an enum type, which in delphi would look like:

--------------------------------------------------------
Type
TOperator = ( opPlus, opMinus, opDivide, opMul, opUnaryMinus );

Var
operator : TOperator;
...

operator := opPlus

--------------------------------------------------------

How do i do that in C#?

If i define:
enum TOperator { opPlus, opMinus, opDivide, opMul, opUnaryMinus };
that's a variable definition, not a class def, right? And i couldn't do:

TOperator op = opPlus; //???

Do i do it this way: Type op = Typeof(TOperator); //?

Thank you,
Andrey
 
Andrey,

Actually, this is a type definition:

public enum TOperator { opPlus, opMinus, opDivide, opMul, opUnaryMinus };

And what you had for the variable needs to be:

TOperator op = TOperator.opPlus;

Values in enumerations need to be preceeded by the enumeration name.

Hope this helps.
 
Back
Top