100k并不是一个太大的数字,所以你可以只是弹出一个Hashset<string>.
Hashset查找是基于密钥的,所以它会很快.
示例在代码中看起来如何:
string[] lines = File.ReadAllLines(@"C:\MyDictionary.txt");
HashSet<string> myDictionary = new HashSet<string>();
foreach (string line in lines)
{
myDictionary.Add(line);
}
string word = "aadvark";
if (myDictionary.Contains(word))
{
Console.WriteLine("There is an aadvark");
}
else
{
Console.WriteLine("The aadvark is a lie");
}
Run Code Online (Sandbox Code Playgroud)