รับการแสดงสตริงของค่า Enum โดยใช้ 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