C# 列舉 GetValues 方法
獲取指定列舉中常量的值的陣列。
這是我們的列舉。
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
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP