c# - Set one enum equal to another -


i have 2 enums in 2 different objects. want set enum in object #1 equal enum in object #2.

here 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 this, wont compile:

 mvc1.obj1 obj1 = new mvc1.obj1();  mvc2.obj2 obj2 = new mvc2.obj2();  obj1.enum1 = obj2.enum1; //i know won't work. 

how set enum in obj1 equal enum in obj2? thanks

assuming keep them same, can cast to/from int:

obj1.enum1 = (mvc1.myenum)((int)obj2.enum1); 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -