我有一个我需要引用的错误代码列表,有点像这样:
Code / Error Message
A01 = whatever error
U01 = another error
U02 = yet another error type
Run Code Online (Sandbox Code Playgroud)
我通过Web服务调用将代码返回给我,我需要显示或获取可读错误.所以我在传递一个返回可读描述的代码时需要一个函数.我只是想做一个选择案例,但认为他们可能是一个更好的方法.这样做的最好的方法/最有效的方法是什么?
使用Dictionary,(在C#中,但概念和类是相同的):
// Initialize this once, and store it in the ASP.NET Cache.
Dictionary<String,String> errorCodes = new Dictionary<String,String>();
errorCodes.Add("A01", "Whatever Error");
errorCodes.Add("U01", "Another Error");
// And to get your error code:
string ErrCode = errorCodes[ErrorCodeFromWS];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6473 次 |
| 最近记录: |