【发布时间】:2015-11-18 06:01:37
【问题描述】:
我这里有一个错误代码,因为我无法检查 string 是否等于 string[]。
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[] options。我真的很想有一个可以用于其余方法的简洁模板。有人可以帮忙吗?
【问题讨论】:
-
我相信
setting.Any应该是option.Any如果我理解你的问题 -
是的,这是一个错字。无论如何,对不起重复。我不敢相信在发布之前我找不到该主题。
标签: c# arrays string linq if-statement