SortedSet<T> Konstruktory

Definicja

Inicjuje nowe wystąpienie klasy SortedSet<T>.

Przeciążenia

SortedSet<T>()

Inicjuje nowe wystąpienie klasy SortedSet<T>.

SortedSet<T>(IComparer<T>)

Inicjuje SortedSet<T> nowe wystąpienie klasy, która używa określonego porównującego.

SortedSet<T>(IEnumerable<T>)

Inicjuje SortedSet<T> nowe wystąpienie klasy zawierające elementy skopiowane z określonej kolekcji wyliczalnej.

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

Inicjuje SortedSet<T> nowe wystąpienie klasy zawierające elementy skopiowane z określonej kolekcji wyliczalnej i które używa określonego modułu porównującego.

SortedSet<T>(SerializationInfo, StreamingContext)
Przestarzałe.

Inicjuje SortedSet<T> nowe wystąpienie klasy zawierającej serializowane dane.

Uwagi

Ten konstruktor jest operacją O(1) .

SortedSet<T>()

Źródło:
SortedSet.cs
Źródło:
SortedSet.cs
Źródło:
SortedSet.cs

Inicjuje nowe wystąpienie klasy SortedSet<T>.

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

Dotyczy

SortedSet<T>(IComparer<T>)

Źródło:
SortedSet.cs
Źródło:
SortedSet.cs
Źródło:
SortedSet.cs

Inicjuje SortedSet<T> nowe wystąpienie klasy, która używa określonego porównującego.

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>

Domyślny porównujący używany do porównywania obiektów.

Wyjątki

comparer to null.

Przykłady

W poniższym przykładzie zdefiniowano moduł porównujący (ByFileExtension), który jest używany do konstruowania posortowanego zestawu, który sortuje nazwy plików według ich rozszerzeń. Ten przykład kodu jest częścią większego przykładu udostępnionego SortedSet<T> dla klasy .

// 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

Dotyczy

SortedSet<T>(IEnumerable<T>)

Źródło:
SortedSet.cs
Źródło:
SortedSet.cs
Źródło:
SortedSet.cs

Inicjuje SortedSet<T> nowe wystąpienie klasy zawierające elementy skopiowane z określonej kolekcji wyliczalnej.

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>

Kolekcja, która ma zostać skopiowana.

Uwagi

Zduplikowane elementy w kolekcji wyliczalnej nie są kopiowane do nowego wystąpienia SortedSet<T> klasy i nie są zgłaszane żadne wyjątki.

Ten konstruktor jest operacją O(n log n) , gdzie n jest liczbą elementów w parametrze collection .

Dotyczy

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

Źródło:
SortedSet.cs
Źródło:
SortedSet.cs
Źródło:
SortedSet.cs

Inicjuje SortedSet<T> nowe wystąpienie klasy zawierające elementy skopiowane z określonej kolekcji wyliczalnej i które używa określonego modułu porównującego.

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>

Kolekcja, która ma zostać skopiowana.

comparer
IComparer<T>

Domyślny porównujący używany do porównywania obiektów.

Wyjątki

collection to null.

Dotyczy

SortedSet<T>(SerializationInfo, StreamingContext)

Źródło:
SortedSet.cs
Źródło:
SortedSet.cs
Źródło:
SortedSet.cs

Przestroga

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

Inicjuje SortedSet<T> nowe wystąpienie klasy zawierającej serializowane dane.

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

Obiekt zawierający informacje wymagane do serializacji SortedSet<T> obiektu.

context
StreamingContext

Struktura zawierająca źródło i miejsce docelowe serializowanego strumienia skojarzonego z obiektem SortedSet<T> .

Atrybuty

Uwagi

Ten konstruktor jest wywoływany podczas deserializacji w celu odtworzenia obiektu, który jest przesyłany przez strumień.

Dotyczy