Enum type def

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
 
N

Nicholas Paldino [.NET/C# MVP]

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
I have small probalem 4
Enum type from one of its members 2
Dictionary 3
Enum To String 14
q: enum as a param 21
Casting as an enum type 2

Top