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 @Naji Afache ,
Thanks for your question.
The slowness might be happening because the loop searches the entire InitialData list from the very beginning for every single item, using a text string (CombFilter).
I recommend using a LINQ Join. This approach attempts to line up both lists and find matches in a single step, which might help avoid searching the same data multiple times.
You can refer to these code example:
var targetSpecs = lstRankRangeSumRankPartition.Where(x => x.Percentage <= 50);
var FilteredData = InitialData.Join(
targetSpecs,
data => new { data.RankRange0Count, data.RankRange1Count, data.RankRange2Count, data.RankRange3Count, data.RankRange4Count, data.TotalSum, RankSum = data.TotalFrequency },
spec => new { spec.RankRange0Count, spec.RankRange1Count, spec.RankRange2Count, spec.RankRange3Count, spec.RankRange4Count, spec.TotalSum, RankSum = spec.RankSum },
(data, spec) => data
).ToList();
Note: this assumes lstRankRangeSumRankPartition is already ordered so that Percentage <= 50 selects the same specs your original break did. If ordering matters in the output, add an OrderBy at the end.
I hope this addresses your question. If this response was helpful, please consider following the guidance to provide feedback. Thank you.