Run Code  | Code Wall  | Users  | Misc  | Feedback  | About  | Login  | Theme  | Privacy 

Cast int to enum in C#

      
            
                
            
 run  | edit  | history  | help 0

Here is also a quick snippet on how to cast an int to enum in C#:

public enum Color {

Red = 1,
Green = 2,
Blue = 3

}

Color c = (Color)3;

//Result: c = Blue

Color c = (Color)4;

//Result: c = 4

  by  programmerdude, 11 months ago




Please log in to post a comment.