You could convert your listClassiNode
into some kind of HashSet
, so that lookups are O(1)
rather than O(n)
.
var hash = new HashSet<string>(
listClassiNode.Select(t =>
string.Format("{0}_{1}", t.Exch, t.Instrument)).Distinct());
List<SecurityInfo> listSecurityInfo = SecurityInfoMasterList.Where(c =>
hash.Contains(string.Format("{0}_{1}", c.SX, c.Instrument))
.ToList();
The above is a little clumsy, with the string.Format
creating a concatenated key to use for the HashSet. Hopefully, the nature of your data is such that it won't be a problem. Anyway, you get the idea, I hope.