列挙型のすべての要素を得るには、Enum.GetValues() や Enum.GetNames() を使います。
private enum UserType {
Guest = 1,
Member,
VIP,
Refused = 99
}
private void SomeMethod(){
foreach(UserType type in Enum.GetValues(typeof(UserType))){
System.Console.Write(type + ” = ” + ((int) type)+ “\n”);
}
}
結果:
Guest = 1
Member = 2
VIP = 3
Refused = 99