【发布时间】:2013-12-01 06:08:27
【问题描述】:
我有以下代码打开一个文本文件并读取文件中的所有行并将其存储到字符串数组中。
然后检查字符串是否存在于数组中。 但是我面临的问题是,每当找到一个字符串时,它总是显示 “有一个匹配” 以及“没有匹配”。 知道如何解决这个问题吗?
检查此代码:
using (StreamReader sr = File.OpenText(path))
{
string[] lines = File.ReadAllLines(path);
for (int x = 0; x < lines.Length - 1; x++)
{
if (domain == lines[x])
{
sr.Close();
MessageBox.Show("there is a match");
}
}
if (sr != null)
{
sr.Close();
MessageBox.Show("there is no match");
}
}
【问题讨论】:
标签: c# string streamreader