有没有一种方法可以使比较短一些

问题描述 投票:0回答:1

我该如何缩短它?

string veryLongVariableName;

if (veryLongVariableName == "a" || veryLongVariableName == "b" || veryLongVariableName == "c"|| veryLongVariableName == "d"|| veryLongVariableName == "e"|| veryLongVariableName == "f")

可能会这样吗?

if (veryLongVariableName == ("a", "b", "c", "d", "e", "f"))
if (veryLongVariableName == ("a" || "b" || "c" || "d" || "e" || "f"))
c# tuples comparison
1个回答
3
投票

您差一点就拥有了

© www.soinside.com 2019 - 2024. All rights reserved.