Set one enum equal to another
.net, c#, enums
Solution
Assuming that you keep them the same, you can cast to/from int:
obj1.enum1 = (MVC1.MyEnum)((int)obj2.enum1);
Problem
I have 2 enums in 2 different objects. I want to set the `enum` in object #1 equal to the `enum` in object #2. Here are my objects: ``` namespace MVC1 { public enum MyEnum { firstName, lastName } public class Obj1{ public MyEnum enum1; } } namespace MVC2 { public enum MyEnum { firstName, lastName } public class Obj2{ public MyEnum enum1; } } ``` I want to do this, but this wont compile: ``` MVC1.Obj1 obj1 = new MVC1.Obj1(); MVC2.Obj2 obj2 = new MVC2.Obj2(); obj1.enum1 = obj2.enum1; //I know this won't work. ``` How do I set the enum in Obj1 equal to the enum in Obj2? Thanks