SortedSet<T> Konstruktory

Definice

Inicializuje novou instanci SortedSet<T> třídy .

Přetížení

SortedSet<T>()

Inicializuje novou instanci SortedSet<T> třídy .

SortedSet<T>(IComparer<T>)

Inicializuje novou instanci SortedSet<T> třídy, která používá zadaný porovnávač.

SortedSet<T>(IEnumerable<T>)

Inicializuje novou instanci SortedSet<T> třídy, která obsahuje prvky zkopírované ze zadané kolekce výčtu.

SortedSet<T>(IEnumerable<T>, IComparer<T>)

Inicializuje novou instanci SortedSet<T> třídy, která obsahuje prvky zkopírované ze zadané kolekce výčtu a která používá zadaný porovnávač.

SortedSet<T>(SerializationInfo, StreamingContext)
Zastaralé.

Inicializuje novou instanci SortedSet<T> třídy, která obsahuje serializovaná data.

Poznámky

Tento konstruktor je O(1) operace.

SortedSet<T>()

Zdroj:
SortedSet.cs
Zdroj:
SortedSet.cs
Zdroj:
SortedSet.cs

Inicializuje novou instanci SortedSet<T> třídy .

public:
 SortedSet();
public SortedSet ();
Public Sub New ()

Platí pro

SortedSet<T>(IComparer<T>)

Zdroj:
SortedSet.cs
Zdroj:
SortedSet.cs
Zdroj:
SortedSet.cs

Inicializuje novou instanci SortedSet<T> třídy, která používá zadaný porovnávač.

public:
 SortedSet(System::Collections::Generic::IComparer<T> ^ comparer);
public SortedSet (System.Collections.Generic.IComparer<T> comparer);
public SortedSet (System.Collections.Generic.IComparer<T>? comparer);
new System.Collections.Generic.SortedSet<'T> : System.Collections.Generic.IComparer<'T> -> System.Collections.Generic.SortedSet<'T>
Public Sub New (comparer As IComparer(Of T))

Parametry

comparer
IComparer<T>

Výchozí porovnávací nástroj pro porovnávání objektů.

Výjimky

comparer je null.

Příklady

Následující příklad definuje porovnávací nástroj (ByFileExtension), který se používá k vytvoření seřazené sady, která seřadí názvy souborů podle jejich přípon. Tento příklad kódu je součástí většího příkladu SortedSet<T> pro třídu .

// Create a sorted set using the ByFileExtension comparer.
var mediaFiles1 = new SortedSet<string>(new ByFileExtension());
' Create a sorted set using the ByFileExtension comparer.
Dim mediaFiles1 As New SortedSet(Of String)(New ByFileExtension)
// Defines a comparer to create a sorted set
// that is sorted by the file extensions.
public class ByFileExtension : IComparer<string>
{
    string xExt, yExt;

    CaseInsensitiveComparer caseiComp = new CaseInsensitiveComparer();

    public int Compare(string x, string y)
    {
        // Parse the extension from the file name.
        xExt = x.Substring(x.LastIndexOf(".") + 1);
        yExt = y.Substring(y.LastIndexOf(".") + 1);

        // Compare the file extensions.
        int vExt = caseiComp.Compare(xExt, yExt);
        if (vExt != 0)
        {
            return vExt;
        }
        else
        {
            // The extension is the same,
            // so compare the filenames.
            return caseiComp.Compare(x, y);
        }
    }
}
' Defines a comparer to create a sorted set
' that is sorted by the file extensions.
Public Class ByFileExtension
    Implements IComparer(Of String)
    Dim xExt, yExt As String

    Dim caseiComp As CaseInsensitiveComparer = _
                        New CaseInsensitiveComparer
    Public Function Compare(x As String, y As String) _
        As Integer Implements IComparer(Of String).Compare
        ' Parse the extension from the file name.
        xExt = x.Substring(x.LastIndexOf(".") + 1)
        yExt = y.Substring(y.LastIndexOf(".") + 1)

        ' Compare the file extensions.
        Dim vExt As Integer = caseiComp.Compare(xExt, yExt)
        If vExt <> 0 Then
            Return vExt
        Else
            ' The extension is the same, 
            ' so compare the filenames. 
            Return caseiComp.Compare(x, y)
        End If
    End Function        
    
End Class

Platí pro

SortedSet<T>(IEnumerable<T>)

Zdroj:
SortedSet.cs
Zdroj:
SortedSet.cs
Zdroj:
SortedSet.cs

Inicializuje novou instanci SortedSet<T> třídy, která obsahuje prvky zkopírované ze zadané kolekce výčtu.

public:
 SortedSet(System::Collections::Generic::IEnumerable<T> ^ collection);
public SortedSet (System.Collections.Generic.IEnumerable<T> collection);
new System.Collections.Generic.SortedSet<'T> : seq<'T> -> System.Collections.Generic.SortedSet<'T>
Public Sub New (collection As IEnumerable(Of T))

Parametry

collection
IEnumerable<T>

Výčtová kolekce, která se má zkopírovat.

Poznámky

Duplicitní prvky v výčtu kolekce nejsou zkopírovány do nové instance SortedSet<T> třídy a nejsou vyvolána žádné výjimky.

Tento konstruktor je O(n log n) operace, kde n je počet prvků v parametru collection .

Platí pro

SortedSet<T>(IEnumerable<T>, IComparer<T>)

Zdroj:
SortedSet.cs
Zdroj:
SortedSet.cs
Zdroj:
SortedSet.cs

Inicializuje novou instanci SortedSet<T> třídy, která obsahuje prvky zkopírované ze zadané kolekce výčtu a která používá zadaný porovnávač.

public:
 SortedSet(System::Collections::Generic::IEnumerable<T> ^ collection, System::Collections::Generic::IComparer<T> ^ comparer);
public SortedSet (System.Collections.Generic.IEnumerable<T> collection, System.Collections.Generic.IComparer<T> comparer);
public SortedSet (System.Collections.Generic.IEnumerable<T> collection, System.Collections.Generic.IComparer<T>? comparer);
new System.Collections.Generic.SortedSet<'T> : seq<'T> * System.Collections.Generic.IComparer<'T> -> System.Collections.Generic.SortedSet<'T>
Public Sub New (collection As IEnumerable(Of T), comparer As IComparer(Of T))

Parametry

collection
IEnumerable<T>

Výčtová kolekce, která se má zkopírovat.

comparer
IComparer<T>

Výchozí porovnávací nástroj pro porovnávání objektů.

Výjimky

collection je null.

Platí pro

SortedSet<T>(SerializationInfo, StreamingContext)

Zdroj:
SortedSet.cs
Zdroj:
SortedSet.cs
Zdroj:
SortedSet.cs

Upozornění

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

Inicializuje novou instanci SortedSet<T> třídy, která obsahuje serializovaná data.

protected:
 SortedSet(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
protected SortedSet (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected SortedSet (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Collections.Generic.SortedSet<'T> : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Collections.Generic.SortedSet<'T>
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Collections.Generic.SortedSet<'T> : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Collections.Generic.SortedSet<'T>
Protected Sub New (info As SerializationInfo, context As StreamingContext)

Parametry

info
SerializationInfo

Objekt, který obsahuje informace potřebné k serializaci objektu SortedSet<T> .

context
StreamingContext

Struktura, která obsahuje zdroj a cíl serializovaného datového proudu přidruženého k objektu SortedSet<T> .

Atributy

Poznámky

Tento konstruktor je volána během deserializace rekonstituovat objekt, který je přenášen přes datový proud.

Platí pro