我有这样的情况:
if (string.IsNullOrEmpty(filename) || size != "Large" || size != "Medium" || size != "Small")
将来我可能不得不在 if
语句中管理更多的 size
。
我想知道是否存在一种更易于管理和可读的方式来编写此条件。
请提供一个真实的例子,感谢您抽出宝贵的时间。
最佳答案
您可以保留一个单词哈希集并检查:
HashSet<string> filterWords = new HashSet<string>();
// Put all words in the hash set
if (filterWords.contains(size))
{
// Do what ever you need
}
关于c# - If 语句的更好语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7077182/