[Mono-list] Enum problem

gennady wexler adyler@winisp.net
Sat, 16 Oct 2004 10:53:35 -0700


On 10/16/04 4:33 AM, "Iain McCoy" <iain@mccoy.id.au> wrote:

> On Sat, 2004-10-16 at 13:17 +0200, Francis Brosnan Bl=E1zquez wrote:
>> Hi.
>>=20
>> Working with enumerations I've found an strange behaviour. If you
>> compile the following source code and run it:
>>=20
>> --
>> using System;
>>=20
>> public class EnumTest {
>>=20
>> public enum TipoCarga {
>> Positivo =3D 1/3,
>> Negativo =3D 1 + (1/3),
>> Neutro   =3D 1,
>> }

> suspect what you're seeing is the compiler automatically coercing all of
> your enum values to ints. This means that 1/3 =3D 0, so 1 + 1/3 =3D 0 and

if 1/3 is 0 then how would 1 + 1/3 be 0 too?

> therefore TipoCarga.Neutro =3D=3D TipoCarga.Negativo. Whether this is what
> css does or not I have no idea, but according to the spec it seems to be
> correct (section 14.3 of the C# language specification 1.2):
> "If the declaration of the enum member has a constant-expression
> initializer, the value of that constant expression, implicitly converted
> to the underlying type of the enum, is the associated value of the enum
> member"

yep I think that is correct. according to that Neg equals to Nut, since the
values are the same it appears that they just get aligned differently (orde=
r
wise) in code by csc and mcs. is it based on alphabetical order perhaps..

in either case, I don't see either compiler doing anything wrong case - no
harm done.