enum Colors : int // byte, sbyte, short, ushort, int, uint, long, ulong
{
Red, Green, Blue, Yellow
};
enum Styles { Plaid, Striped, Tartan, Corduroy };
public void method()
{
Colors myColor = Colors.Blue;
string str1 = String.Format("My favorite color is {0}", myColor); //Blue
string str2 = String.Format("The value of my favorite color is {0}", Enum.Format(typeof(Colors), myColor, "d")); //2
string str3 = String.Format("The hex value of my favorite color is {0}", Enum.Format(typeof(Colors), myColor, "x")); //00000002
string str4 = String.Format("The 4th value of the Colors Enum is {0}", Enum.GetName(typeof(Colors), 3)); //Yellow
string str5 = String.Format("The 4th value of the Styles Enum is {0}", Enum.GetName(typeof(Styles), 3)); //Corduroy
string[] str6 = Enum.GetNames(typeof(Colors)); //Red, Green, Blue, Yellow
Array str7 = Enum.GetValues(typeof(Colors)); //Colors.Red, Colors.Green, Colors.Blue, Colors.Yellow
}
Enum Type 중요 메소드들
댓글 없음:
댓글 쓰기