string[] Strarr = NBber.Split('\n'); //获取本地字符串数组
string Snb = txtNumber.Text.Trim();
string[] Stt = Snb.Split('\n'); //获取文本框字符串数组
for (int x = 0; x < Stt.Length; x++)
{
bool exists = ((IList)Strarr).Contains(Stt[x]);//判断单号是否存在
}
重构一下代码
bool exists = Stt.Any(x => Strarr.Contains(x));
下面的测试代码输出是 True
using System.Collections;
string nbber = "001\n002\n003";
string[] Strarr = nbber.Split('\n');
string txtNumberText = "003\n004\n005";
string Snb = txtNumberText.Trim();
string[] Stt = Snb.Split('\n');
bool exists = Stt.Any(x => Strarr.Contains(x));
Console.WriteLine(exists);
我试下,谢谢大佬
调试一下吗,循环多次,每次都给 变量exists ,返回true也没break
另外看起来是比较2个list,试试取交集、并集、差集的方法吧
嗯呢