如何将hashset
与文件内容进行比较?
我想要某种循环,将文件内容与hashset
进行比较,然后在hashset
中的位置停止,如果它在文件中找不到相同的内容
答案 0 :(得分:1)
示例
string[] array1 = { "cat", "dog", "cat", "leopard", "tiger", "cat" };
var hash = new HashSet<string>(array1);
string f = "TextFile1.txt";
using (StreamReader r = new StreamReader(f))
{
string line;
while ((line = r.ReadLine()) != null)
{
if(!hash.Contains(line))
break;
}
}