我这里有一个错误代码,因为我无法检查字符串是否等于字符串[]。
public void SetCh1Probe(string input)
{
string[] option= {"1:1", "1:10", "1:100"}
//I wanna check if input is equal to any of the string array
if (input != option.Any(x => x == option))
{
MessageBox.Show("Invalid Input");
}
else
{
//Proceed with other stuffs
}
}
我会有大量这样的方法,每个方法都有不同的string[] 选项
。我真的很想拥有一个可以用于其余方法的简洁模板。有人可以帮忙吗?
最佳答案
改变你的条件从
if (input != option.Any(x => x == option))
到
if (!option.Any(x => x == input))
或者另一种选择
if (option.All(x => x != input))
关于C# Linq - 如果输入不等于任何字符串 [],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33772838/