Note that there are some explanatory texts on larger screens.

plurals
  1. POOverload List.Sort
    primarykey
    data
    text
    <p>I have a <code>List(Of MyObject)</code> that I need to sort. So I've made sure to implement <code>IComparable</code>, <code>IEquatable</code>, <code>IEqualityComparer</code>, and <code>IComparer</code> and sorting works fine.</p> <p>There is new a new requirement for the project. A sorted list can not contain 'duplicate' objects. Duplicate in this case is slightly different than how duplicate is defined for sorting purposes. I've created a new routine that will check two objects and return the preferred one. The preferred one is the one that has all values the same except for one and that last value is the biggest. I've gotten this routine working well.</p> <p>Now I would love to solve this 'remove duplicates' issue by creating an object that inherits <code>IList(Of MyObject)</code> and then overriding the <code>Sort</code> method to first remove 'duplicates' and then to sort using the <code>IComparable</code> interface as a <code>List</code> would normally sort itself. However, I have no idea how to do this. It doesn't even seem possible from what I've read so far. I know I could solve this by just creating a separate routine like <code>SortWithRemove</code> or something like that, but I was wondering if overriding is possible.</p> <p>Edit: Based on the suggestions below I decided not to override <code>Sort</code> but to use an extension method. Here is my code:</p> <pre><code>Public Module Extensions &lt;System.Runtime.CompilerServices.Extension()&gt; _ Public Sub SortRemovingDuplicates(list As List(Of UniCatalogEntry)) 'filter out unwanted records End Sub End Module </code></pre>
    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.
 

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