I am having 100K items in a Dictionary. And I am trying to search 50K items in it. It works but take 2 min which is bad. I tried couple of thing the best I can think is using linq. below is my code. The while loops stops executing after 2 mins.
public static void Day8(Dictionary<string, string> valuePair)
{
Dictionary<string, string> valuePairs = valuePair;
List<string> dataList = new List<string>();
string line;
StreamReader file = new StreamReader("2.txt");
while ((line = file.ReadLine()) != null)
{
var result = valuePairs.FirstOrDefault(a => a.Key == line);
var data = result.Key == null ? "Not found" : $"{result.Key}={result.Value}";
}
dataList.ForEach(Console.WriteLine);
File.WriteAllLines("3.txt", dataList);
}