Converting Enums (c#)

  • Thread starter Thread starter Mark Olbert
  • Start date Start date
M

Mark Olbert

Given:

public enum SomeEnumType : int
{
None = 0,
}

int b = 0;

why does the following cast succeed:

SomeEnumType a = (SomeEnumType) b;

while the following conversion fails:

SomeEnumType a = Convert.ChangeType(b, typeof(SomeEnumType));

Is there a "generic" way of converting integer values into integer-based enums?

- Mark
 
Thank you thank you thank you!! I don't know how I missed that method of Enum, but it neatly solves the problem!

- Mark
 
Back
Top