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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Enum to int type cast 4
Enum Extentions 7
Itereate cross tab query over another query 0
Merge Info From Two Enums 1
enum questions 2
I have small probalem 4
Enums & Constructors? 4
enum with underlying type 1

Back
Top