CollectionsExtensions.SortedInsert<TElement> Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Inserts an item in its sorted position into an already sorted collection. This is useful if you need to consume the collection in between insertions and need it to stay correctly sorted the whole time. If you just need to insert a bunch of items and then consume the sorted collection at the end, it's faster to add all the elements and then use Sort() at the end.
public static int SortedInsert<TElement> (this System.Collections.Generic.List<TElement> elements, TElement toInsert, System.Collections.Generic.IComparer<TElement> comparer = default);
static member SortedInsert : System.Collections.Generic.List<'Element> * 'Element * System.Collections.Generic.IComparer<'Element> -> int
<Extension()>
Public Function SortedInsert(Of TElement) (elements As List(Of TElement), toInsert As TElement, Optional comparer As IComparer(Of TElement) = Nothing) As Integer
Type Parameters
- TElement
The type of element in the collection.
Parameters
- elements
- List<TElement>
The collection of sorted elements to be inserted into.
- toInsert
- TElement
The element to insert.