C# Enum如何透過Name去取得Value
小弟在 Enum 內宣告了不少東西
public enum enum_Channel
{
Ch01 = 0x81,
Ch02,
Ch03,
Ch04,
Ch05,
Ch06,
Ch07,
Ch08,
Ch09,
Ch10,
Ch11,
Ch12,
Ch13,
Ch14,
Ch15,
Ch16,
Ch17,
Ch18,
Ch19,
Ch20,
Ch21,
Ch22,
Ch23,
Ch24,
Ch25,
Ch26,
Ch27,
Ch28,
Ch29,
Ch30,
Ch31,
Ch32,
Ch33,
Ch34,
Ch35,
Ch36,
Ch37,
Ch38,
Ch39,
}
但是我發現如果我要直接把這些東西的內容值取出來,並且印出來,好像辦不到
比方我我想印出Ch39的數值(167),該怎麼印呢?
using System;
public class Program
{
public enum enum_Channel
{
Ch01 = 0x81,
Ch02,
Ch03,
Ch04,
Ch05,
Ch06,
Ch07,
Ch08,
Ch09,
Ch10,
Ch11,
Ch12,
Ch13,
Ch14,
Ch15,
Ch16,
Ch17,
Ch18,
Ch19,
Ch20,
Ch21,
Ch22,
Ch23,
Ch24,
Ch25,
Ch26,
Ch27,
Ch28,
Ch29,
Ch30,
Ch31,
Ch32,
Ch33,
Ch34,
Ch35,
Ch36,
Ch37,
Ch38,
Ch39,
}
public static void Main()
{
Console.WriteLine((int)enum_Channel.Ch39);
}
}