지정된 열거에 있는 상수 값의 배열을 가져옵니다.
여기 우리의 열거가 있습니다.
enum Rank { Jack = 10, Tom = 19, Tim = 26 }; 이제 열거형의 모든 값을 배열로 가져와 GetValues() 메서드를 사용하여 표시합니다.
foreach(int res in Enum.GetValues(typeof(Rank))) {
Console.WriteLine(res);
} 전체 예를 살펴보겠습니다.
예시
using System;
public class Demo {
enum Rank { Jack = 10, Tom = 19, Tim = 26 };
public static void Main() {
Console.WriteLine("Here are the university rank of MCA Students College ABC:");
foreach(int res in Enum.GetValues(typeof(Rank))) {
Console.WriteLine(res);
}
}
} 출력
Here are the university rank of MCA Students College ABC: 10 19 26