我有一个包含字符串值的列表arrString
。我需要在C#中使用for循环检查字符串lookupvalue.Longname
是否存在于列表中。
for(int i = 0 ;i < ResoCustomFields.LongnameNotToBeTaken.Count ;i++)
{
string myStringList = ResoCustomFields.LongnameNotToBeTaken[i].ToString();
var arrString = myStringList.Trim('(',')').Split(',').ToList();
if(arrString.Contains(resoField))
{
// if(!arrString[i].Any(str=>str.ToString().Contains(lookupValue.LongName)))
// if(lookupValue.LongName.Contains(arrString.ToString()))
//(!arrString.Any(str => str.Equals(lookupValue.LongName)))
// if(!arrString.Equals(lookupValue.LongName))
{
}
}
答案 0 :(得分:0)
您可以尝试以下代码:
int pos = Array.IndexOf(arrString, lookupValue.LongName);
if (pos > -1)
{
//// DO YOUR STUF
}
以下是参考:
Checking if a string array contains a value, and if so, getting its position