N
Nathan Baulch
I'm having issues working with some legacy enums that have multiple zero
values.
Whenever I try to call ToString() on one of the non-zero values, all but the
first zero value is included.
Is there any way to get the non-zero value name without resorting to string
manipulation or manually iterating through all values?
[Flags]
enum TestEnum
{
Zero = 0,
AlsoZero = 0,
NonZero = 1
}
static void Main()
{
//all of these output "AlsoZero, NonZero"
Console.WriteLine(TestEnum.NonZero);
Console.WriteLine(Convert.ToString(TestEnum.NonZero));
Console.WriteLine(TypeDescriptor.GetConverter(typeof(TestEnum)).ConvertToString(TestEnum.NonZero));
}
Cheers,
Nathan
values.
Whenever I try to call ToString() on one of the non-zero values, all but the
first zero value is included.
Is there any way to get the non-zero value name without resorting to string
manipulation or manually iterating through all values?
[Flags]
enum TestEnum
{
Zero = 0,
AlsoZero = 0,
NonZero = 1
}
static void Main()
{
//all of these output "AlsoZero, NonZero"
Console.WriteLine(TestEnum.NonZero);
Console.WriteLine(Convert.ToString(TestEnum.NonZero));
Console.WriteLine(TypeDescriptor.GetConverter(typeof(TestEnum)).ConvertToString(TestEnum.NonZero));
}
Cheers,
Nathan