I can not find a concrete example of this, so I am posting a question. Any help was appreciated.
I have two large general lists that contain more than 300 thousand items.
I look at the first list to discard information and generate a new item for the new list on the fly, but I need to search the second list and return a value based on three matching criteria, if found add it to the list, however, as you can imagine it 300k * 300k times takes time.
Is there a way to do this more efficiently?
My code is:
var reportList = new List<StocksHeldInCustody>(); foreach (var correctDepotHolding in correctDepotHoldings) { var reportLine = new StocksHeldInCustody(); reportLine.ClientNo = correctDepotHolding.ClientNo; reportLine.Value = correctDepotHolding.ValueOfStock; reportLine.Depot = correctDepotHolding.Depot; reportLine.SEDOL = correctDepotHolding.StockCode; reportLine.Units = correctDepotHolding.QuantityHeld; reportLine.Custodian = "Unknown"; reportLine.StockName = correctDepotHolding.StockR1.Trim() + " " + correctDepotHolding.StockR2.Trim(); //Get custodian info foreach (var ccHolding in ccHoldList) { if (correctDepotHolding.ClientNo != ccHolding.ClientNo) continue; if (correctDepotHolding.Depot != ccHolding.Depot) continue; if (correctDepotHolding.StockCode != ccHolding.StockCode) continue; if (correctDepotHolding.QuantityHeld != ccHolding.QuantityHeld) continue; reportLine.Custodian = ccHolding.Custodian; break; } reportList.Add(reportLine); }
source share