[Mono-list] Enum problem
Francis Brosnan Blázquez
francis@aspl.es
Sat, 16 Oct 2004 13:17:01 +0200
Hi.
Working with enumerations I've found an strange behaviour. If you
compile the following source code and run it:
--
using System;
public class EnumTest {
public enum TipoCarga {
Positivo = 1/3,
Negativo = 1 + (1/3),
Neutro = 1,
}
public static void Main () {
TipoCarga carga;
carga = TipoCarga.Positivo;
Console.WriteLine ("carga value is: {0}", carga);
carga = TipoCarga.Neutro;
Console.WriteLine ("carga value is: {0}", carga);
carga = TipoCarga.Negativo;
Console.WriteLine ("carga value is: {0}", carga);
}
}
--
You get the following output:
carga value is: Positivo
carga value is: Neutro
carga value is: Neutro
That is, on every assignment which uses TipoCarga.Negativo doesn't work.
I've been reading about how enumerations works and seens to be that you
can only use values from byte, sbyte, short, ushort, int, uint, long, or
ulong types but not float or double types which can hold values as 1/3
and 1 + (1/3).
The odd thing is that assignment for Positivo = 1/3 works perfectly.
Maybe mcs mustn't allow someone to compile the previous source code?
.- Francis