我有一个在类中声明的1000个const变量的列表.我在保存记录时存储id,在检索时,我必须显示文本.例
public const uint ZenitStPetersburg = 100769;
Run Code Online (Sandbox Code Playgroud)
因此,在检索时,我必须展示ZenitStPetersburg
现在,我正在做切换案例,是否有任何优雅的解决方案来检索文本?
是的,而不是变量,利用Dictionary<uint, string>:
private Dictionary<uint, string> _constants = new Dictionary<uint, string>
{
{ 100769, "ZenitStPetersburg" }
}
Run Code Online (Sandbox Code Playgroud)
然后在字典中查找:
var val = _constants[uintValue];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
63 次 |
| 最近记录: |