【发布时间】:2016-11-16 06:35:31
【问题描述】:
假设我有这个代码。
int count = 0;
int id = GetFirstId();
count = getCountById(id);
if(count == 0){
id = GetSecondId();
count = getCountById(id);
if(count == 0){
id = GetThirdId();
count = getCountById(id);
}
}
有没有更好的方法来做到这一点。内部的 LOOP 和 CASE 语句之类的东西更好吗?
【问题讨论】:
-
您使用的是什么编程语言?
-
C# 但我认为这种做法也应该应用于其他编程语言?
-
如果您有很多物品,您绝对应该使用开关。
标签: c# if-statement logic