SortedSet<T> Costruttori

Definizione

Inizializza una nuova istanza della classe SortedSet<T>.

Overload

SortedSet<T>()

Inizializza una nuova istanza della classe SortedSet<T>.

SortedSet<T>(IComparer<T>)

Inizializza una nuova istanza della classe SortedSet<T> che usa un operatore di confronto specificato.

SortedSet<T>(IEnumerable<T>)

Inizializza una nuova istanza della classe SortedSet<T> che contiene elementi copiati da una raccolta enumerabile specificata.

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

Inizializza una nuova istanza della classe SortedSet<T> che contiene elementi copiati da una raccolta enumerabile specificata e che usa un operatore di confronto specificato.

SortedSet<T>(SerializationInfo, StreamingContext)
Obsoleti.

Inizializza una nuova istanza della classe SortedSet<T> che contiene dati serializzati.

Commenti

Questo costruttore è un'operazione O(1) .

SortedSet<T>()

Source:
SortedSet.cs
Source:
SortedSet.cs
Source:
SortedSet.cs

Inizializza una nuova istanza della classe SortedSet<T>.

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

Si applica a

SortedSet<T>(IComparer<T>)

Source:
SortedSet.cs
Source:
SortedSet.cs
Source:
SortedSet.cs

Inizializza una nuova istanza della classe SortedSet<T> che usa un operatore di confronto specificato.

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

Parametri

comparer
IComparer<T>

Operatore di confronto predefinito da usare per il confronto degli oggetti.

Eccezioni

comparer è null.

Esempio

Nell'esempio seguente viene definito un operatore di confronto (ByFileExtension) utilizzato per costruire un set ordinato che ordina i nomi di file in base alle relative estensioni. Questo esempio di codice fa parte di un esempio più ampio fornito per la SortedSet<T> classe .

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

Si applica a

SortedSet<T>(IEnumerable<T>)

Source:
SortedSet.cs
Source:
SortedSet.cs
Source:
SortedSet.cs

Inizializza una nuova istanza della classe SortedSet<T> che contiene elementi copiati da una raccolta enumerabile specificata.

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

Parametri

collection
IEnumerable<T>

Raccolta enumerabile da copiare.

Commenti

Gli elementi duplicati nella raccolta enumerabile non vengono copiati nella nuova istanza della SortedSet<T> classe e non vengono generate eccezioni.

Questo costruttore è un'operazione O(n log n) , dove n è il numero di elementi nel collection parametro .

Si applica a

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

Source:
SortedSet.cs
Source:
SortedSet.cs
Source:
SortedSet.cs

Inizializza una nuova istanza della classe SortedSet<T> che contiene elementi copiati da una raccolta enumerabile specificata e che usa un operatore di confronto specificato.

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

Parametri

collection
IEnumerable<T>

Raccolta enumerabile da copiare.

comparer
IComparer<T>

Operatore di confronto predefinito da usare per il confronto degli oggetti.

Eccezioni

collection è null.

Si applica a

SortedSet<T>(SerializationInfo, StreamingContext)

Source:
SortedSet.cs
Source:
SortedSet.cs
Source:
SortedSet.cs

Attenzione

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

Inizializza una nuova istanza della classe SortedSet<T> che contiene dati serializzati.

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)

Parametri

info
SerializationInfo

Oggetto contenente le informazioni necessarie per serializzare l'oggetto SortedSet<T>.

context
StreamingContext

Struttura contenente l'origine e la destinazione del flusso serializzato associato all'oggetto SortedSet<T>.

Attributi

Commenti

Questo costruttore viene chiamato durante la deserializzazione per ricostituire un oggetto trasmesso su un flusso.

Si applica a