在 C# 中,不是执行 if(index == 7 || index == 8)
,有没有办法将它们结合起来?我在想类似 if(index == (7, 8))
的东西。
最佳答案
您可以使用扩展方法完成此操作。
public static bool In<T>(this T obj, params T[] collection) {
return collection.Contains(obj);
}
然后...
if(index.In(7,8))
{
...
}
关于c# - 在 C# 中组合多个条件表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6390138/