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