T
The Last Gunslinger
We have an enum:
public enum EnumDays
{
Sun = 1,
Mon = 2,
...
}
We can store it as a byte:
byte ByteEnum = (byte)EnumDays.Sun;
We can cast it back to EnumDays:
EnumDays Days = (EnumDays)ByteEnum;
But we cannot Convert it using ChangeType:
Object EnumObject = Convert.ChangeType(ByteEnum, typeof(EnumDays));
Results in an InvalidCastException: Cannot convert from system.byte to
namespace.EnumDays.
Why does this not work.
I need to be able to do this so I can set a property of type EnumDays on
a class using reflection.
Any help much appreciated.
Cheers
JB

public enum EnumDays
{
Sun = 1,
Mon = 2,
...
}
We can store it as a byte:
byte ByteEnum = (byte)EnumDays.Sun;
We can cast it back to EnumDays:
EnumDays Days = (EnumDays)ByteEnum;
But we cannot Convert it using ChangeType:
Object EnumObject = Convert.ChangeType(ByteEnum, typeof(EnumDays));
Results in an InvalidCastException: Cannot convert from system.byte to
namespace.EnumDays.
Why does this not work.
I need to be able to do this so I can set a property of type EnumDays on
a class using reflection.
Any help much appreciated.
Cheers
JB
