Here a sample program demonstrating how to convert between any of these formats.
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication2 {
public enum Color {
red,
white,
blue
}
class Program {
static void Main(string[] args) {
string toString, fromString = "red";
int toInt, fromInt = 1;
Color toColor, fromColor = Color.blue;
// string to enum
toColor = (Color) Enum.Parse(typeof(Color), fromString);
// string to int
toInt = (int) (Color) Enum.Parse(typeof(Color), fromString);
// int to enum
toColor = (Color) fromInt;
// int to string
toString = ((Color) fromInt).ToString();
// enum to string
toString = fromColor.ToString();
// enum to int
toInt = (int) fromColor;
Console.ReadLine();
}
}
}