An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
Hello @Jonathan ,
Thanks for your question.
Instead of applying SearchValues + Parallel.ForEach to your existing List, I would suggest a simpler and more effective approach - replace List<string> with HashSet<string>.
You can refer to my example code:
var ipSet = new HashSet<string>(
File.Exists(@"c:/cmp/list11.txt")
? File.ReadLines(@"c:/cmp/list11.txt").Select(l => l.Trim())
: Enumerable.Empty<string>(),
StringComparer.OrdinalIgnoreCase
);
public static bool AddIfNotExists(string ip, HashSet<string> ipSet)
{
ip = ip.Trim();
if (ipSet.Add(ip))
{
File.AppendAllText(@"c:/cmp/list11.txt", ip + Environment.NewLine);
return true;
}
return false;
}
I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback.