Gib*_*boK 4 .net c# if-statement
我有这样一个条件:
if (string.IsNullOrEmpty(filename) || size != "Large" || size != "Medium" || size != "Small")
Run Code Online (Sandbox Code Playgroud)
未来的可能性我将不得不size
在if
声明中管理更多.
我想知道是否存在一种更易于管理和可读的方式来编写这种情况.
请提供一个真实的例子,感谢您的时间.
你可以保留单词的hashset并检查:
HashSet<string> filterWords = new HashSet<string>();
// Put all words in the hash set
if (filterWords.contains(size))
{
// Do what ever you need
}
Run Code Online (Sandbox Code Playgroud)