Converting between Int32 and enum

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
}
Jon Skeet
people
quotationmark

Now that we know that ScaleGroup isn't a class, but an enum, it's simple:

int num = (int) ld.ScaleGroup;
int secondDigit = num % 10;
ld.ScaleGroup = (ScaleGroup) secondDigit;

(It's not clear to me that that's actually what you want, given your enum declaration, but that will perform the relevant conversions...)

people

See more on this question at Stackoverflow