尝试使用 LINQ 重写它:
if (mode != "A" && mode != "B" && mode != "C" && mode != "D" && mode != "E" && mode != "F" && mode != "G")
{
continue;
}
重构它的最清晰简洁的方法是什么?我发誓我以前见过这样的帖子,但我现在找不到了。
最佳答案
您可以使用 Contains
方法来自 IList<T>
:
IList<string> modes = new[]{"A","B","C","D","E","F","G"};
if (!modes.Contains(mode))...
关于c# - 如何检查一个字符串是否不等于所有这些?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13198107/