我看不出任何逻辑,所以我假设映射是外部的。两个选项 - aswitch或字典。
string result;
switch(num) {
case 0: result = "UH"; break;
//...
case 48: result = "OL"; break;
default: throw new ArgumentOutOfRangeException();
}
Console.WriteLine(result);
或者,字典:
static readonly Dictionary<int,string> map = new Dictionary<int,string> {
{0, "UH"},
//...
{48, "OL"}
};
...
string result;
if(!map.TryGetValue(num, out result))
throw new ArgumentOutOfRangeException();
Console.WriteLine(result);
编辑:第三个选项 - 一个enum:
enum Map {
UH = 0,
//...
OL = 48
}
...
Map mapped = (Map)num;
Console.WriteLine(mapped);
// also, string result = mapped.ToString(); if you really need