# [Mono-list] Enum problem

Kirk Marple kirk-public@agnostic-media.com
Sat, 16 Oct 2004 11:28:14 -0700

```The real issue here is about rounding to integers, and enums are ints by
default, so really the numbers are equivalent to:

Positivo =3D 0,
Negativo =3D 1,
Neutro =3D 1

Which would make sense by what you see printed out.

-----Original Message-----
Sent: Saturday, October 16, 2004 10:54 AM
To: Iain McCoy; francis@aspl.es
Cc: mono
Subject: Re: [Mono-list] Enum problem

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=20
>> 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=20
> of your enum values to ints. This means that 1/3 =3D 0, so 1 + 1/3 =3D =
0=20
> 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=20
> css does or not I have no idea, but according to the spec it seems to=20
> be correct (section 14.3 of the C# language specification 1.2):
> "If the declaration of the enum member has a constant-expression=20
> initializer, the value of that constant expression, implicitly=20
> converted to the underlying type of the enum, is the associated value=20
> 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 =
(order
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.

_______________________________________________
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list

```