Nhận biểu diễn chuỗi của một giá trị Enum bằng Enum.GetName.
Nó có hai tham số -
-
Loại - Kiểu liệt kê
-
Đối tượng - Giá trị của một phép liệt kê
Sau đây là một ví dụ -
Ví dụ
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);
}
} Đầu ra
Motorbike