C# 中的 Enum.GetName
使用 Enum.GetName 获取枚举值的字符串表示。
它有两个参数 -
类型 - 枚举类型
对象 - 枚举的值
以下是一个示例 -
示例
using System;
class Demo {
enum Vehicle {
Car,
Motorbike,
Truck,
Bicycles
};
static void Main() {
// Usig GetName to get the string representation of enum type
string res = Enum.GetName(typeof(Vehicle), Vehicle.Motorbike);
// Displaying
Console.WriteLine(res);
}
}输出
Motorbike
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP