I have a custom type called ScaleGroup. I am trying to parse out the data (done) then convert it to ScaleGroup for comparison. ScaleGroup is an enum. I found this method online of conversion but it not working. How can I get the conversion?
Here is my type declaration
public ScaleGroup ScaleGroup { get; set; }
Here is where I need it to change from an Int32 to ScaleGroup
int num = Convert.ToInt32(ld.ScaleGroup);
int secondDigit = num % 10;
ld.ScaleGroup = (ScaleGroup)Convert.ChangeType(
secondDigit, typeof(ScaleGroup));//problem spot
ScaleGroup declaration:
public enum ScaleGroup
{
GROUP_1 = 1,
GROUP_2 = 2,
BOTH = 3
}
Convert.ChangeType, why don't you just provide a constructor forScaleGroupwhich takes anintparameter?int, so anything after that point doesn't need to do any parsing... It's not clear what you mean by "in a reader"