【发布时间】:2011-11-02 03:27:14
【问题描述】:
我正在使用一些代码,它返回一个代码来指示他们是用户的类型(例如“A”、“B”、“C”、“D”等)。每个代码对应一个特定的角色和/或范围(例如,跨整个应用程序或仅针对正在处理的对象)。
在我正在查看的一些代码中,我看到调用来检查用户的代码是否是多个代码之一,以便允许他们执行某些操作。所以我看到这样的电话:
//"B" would come from the database
string userCode = "B";
//some more work...
//if the user's code is either A or C...
if("AC".IndexOf(userCode) >= 0) {
//do work that allows the user to progress
} else {
//notify user they can't do this operation
}
这是执行此检查的有效方法吗?有没有更有效的方法?
提前致谢!
【问题讨论】:
标签: c# performance