Re: Enum type def

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Nicholas Paldino [.NET/C# MVP] (mvp_at_spam.guard.caspershouse.com)
Date: 03/11/04


Date: Thu, 11 Mar 2004 13:27:31 -0500

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.

-- 
               - Nicholas Paldino [.NET/C# MVP]
               - mvp@spam.guard.caspershouse.com
"MuZZy" <leyandrewemail-news@yahoo.com> wrote in message
news:G524c.9133$YG.82387@attbi_s01...
> 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
>
>
>
>