Note that there are some explanatory texts on larger screens.

plurals
  1. POIs there something I can do to optimise my linq query?
    primarykey
    data
    text
    <p>I have to be able to sort out a list of object which might contains doubloon with certain criteria. So far the code is working but it takes 10 minutes for 50,000 rows in my list.</p> <p>Here is the code :</p> <pre><code> public class TestObject { public string value1; public string value2; public string value3; public string value4; public int num1; public int num2; } public static List&lt;TestObject&gt; ReturnTestObjectListWithoutDoubloon(List&lt;TestObject&gt; source) { var destination = new List&lt;TestObject&gt;(); var list = new Dictionary&lt;int, TestObject&gt;(); while (source.Count &gt; 0) { list.Clear(); var originalElement = source[0]; foreach (var query in source.Select((element, index) =&gt; new { Value = element, Index = index }) .Where(currentElement =&gt; (currentElement.Value.value1 == originalElement.value1) &amp;&amp; (currentElement.Value.value2 == originalElement.value2) &amp;&amp; (currentElement.Value.value3 == originalElement.value3) &amp;&amp; (currentElement.Value.value4 == originalElement.value4))) { list.Add(query.Index, query.Value); } if (list.Count &gt; 1) { originalElement.num1 = list.Sum(a =&gt; a.Value.num1); originalElement.num2 = list.Sum(a =&gt; a.Value.num2); } destination.Add(originalElement); foreach (var positionToremove in list.Keys) source.RemoveAt(positionToremove); } return destination; } </code></pre> <p>The idea is to reduce the list each time I pass the while loop so my Linq request is executed on the smallest list possible. However the fewer doubloons I have , the slower it is. I am looking for a solution which allows me to have the smallest rutnime possible, memory is not an issue.</p> <p>Does anyone have an idea ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload