Reputation: 33
Can I improve the performance of this code where in I am trying to search a List of Dictionary (tr) from a List of string (_authorizedBks). Is there any better way to code this in C# or supporting languages in .NET?
for (int i = tr.Count - 1; i >= 0; i--)
{
if (tr[i].ContainsKey("BK") && !_authorizedBks.Contains(tr[i]["BK"], StringComparer.CurrentCultureIgnoreCase))
{
removedBks.Add(tr[i]);
}
}
// where tr is List<Dictionary<string, string>>
// _authorizedBks is List<string>
// removedBks is List<Dictionary<string, string>>
Upvotes: 0
Views: 123
Reputation: 9458
If you want to search in those you can give HashSet<T>
a try? The search in a hashset is amortized at O(1).
HashSet<Dictionary<string, string>> tr = new HashSet<Dictionary<string, string>>();
HashSet<string> _authorizedBks = new HashSet<string>();
Upvotes: 2