我有一个需要引用的错误代码列表,有点像这样:
Code / Error Message
A01 = whatever error
U01 = another error
U02 = yet another error type
我通过网络服务调用获得返回给我的代码,我需要显示或获取可读错误。所以我需要一个函数,当传递一个返回可读描述的代码时。我只想做一个精选案例,但认为他们可能是更好的方法。最好的/最有效的方法是什么?
最佳答案
使用字典(在 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];
关于asp.net - 存储/查找名称值对的最佳方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/306191/