SortedSet<T> Construtores

Definição

Inicializa uma nova instância da classe SortedSet<T>.

Sobrecargas

Nome Description
SortedSet<T>()

Inicializa uma nova instância da classe SortedSet<T>.

SortedSet<T>(IComparer<T>)

Inicializa uma nova instância da SortedSet<T> classe que usa um comparador especificado.

SortedSet<T>(IEnumerable<T>)

Inicializa uma nova instância da SortedSet<T> classe que contém elementos copiados de uma coleção enumerável especificada.

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

Inicializa uma nova instância da SortedSet<T> classe que contém elementos copiados de uma coleção enumerável especificada e que usa um comparador especificado.

SortedSet<T>(SerializationInfo, StreamingContext)

Inicializa uma nova instância da SortedSet<T> classe que contém dados serializados.

Comentários

Este construtor é uma O(1) operação.

SortedSet<T>()

Inicializa uma nova instância da classe SortedSet<T>.

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

Aplica-se a

SortedSet<T>(IComparer<T>)

Inicializa uma nova instância da SortedSet<T> classe que usa um comparador especificado.

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

Parâmetros

comparer
IComparer<T>

O comparador padrão a ser usado para comparar objetos.

Exceções

comparer é null.

Exemplos

O exemplo a seguir define um comparador (ByFileExtension) usado para construir um conjunto classificado que classifica os nomes de arquivo por suas extensões. Este exemplo de código faz parte de um exemplo maior fornecido para a 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

Aplica-se a

SortedSet<T>(IEnumerable<T>)

Inicializa uma nova instância da SortedSet<T> classe que contém elementos copiados de uma coleção enumerável especificada.

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

Parâmetros

collection
IEnumerable<T>

A coleção enumerável a ser copiada.

Comentários

Elementos duplicados na coleção enumerável não são copiados para a nova instância da SortedSet<T> classe e nenhuma exceção é gerada.

Esse construtor é uma O(n log n) operação, onde n está o número de elementos no collection parâmetro.

Aplica-se a

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

Inicializa uma nova instância da SortedSet<T> classe que contém elementos copiados de uma coleção enumerável especificada e que usa um comparador especificado.

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

Parâmetros

collection
IEnumerable<T>

A coleção enumerável a ser copiada.

comparer
IComparer<T>

O comparador padrão a ser usado para comparar objetos.

Exceções

collection é null.

Aplica-se a

SortedSet<T>(SerializationInfo, StreamingContext)

Inicializa uma nova instância da SortedSet<T> classe que contém dados serializados.

protected:
 SortedSet(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
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>
Protected Sub New (info As SerializationInfo, context As StreamingContext)

Parâmetros

info
SerializationInfo

O objeto que contém as informações necessárias para serializar o SortedSet<T> objeto.

context
StreamingContext

A estrutura que contém a origem e o destino do fluxo serializado associado ao SortedSet<T> objeto.

Comentários

Esse construtor é chamado durante a desserialização para reconstituir um objeto transmitido por um fluxo.

Aplica-se a