SortedSet<T> Construtores
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Inicializa uma nova instância da SortedSet<T> classe.
Sobrecargas
| Name | Description |
|---|---|
| SortedSet<T>() |
Inicializa uma nova instância da SortedSet<T> classe. |
| SortedSet<T>(IComparer<T>) |
Inicializa uma nova instância da SortedSet<T> classe que utiliza 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 utiliza um comparador especificado. |
| SortedSet<T>(SerializationInfo, StreamingContext) |
Inicializa uma nova instância da SortedSet<T> classe que contém dados serializados. |
Observações
Este construtor é uma O(1) operação.
SortedSet<T>()
Inicializa uma nova instância da SortedSet<T> classe.
public:
SortedSet();
public SortedSet();
Public Sub New ()
Aplica-se a
SortedSet<T>(IComparer<T>)
Inicializa uma nova instância da SortedSet<T> classe que utiliza 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 usar para comparar objetos.
Exceções
comparer é null.
Exemplos
O exemplo seguinte define um comparador (ByFileExtension) que é usado para construir um conjunto ordenado que ordena nomes de ficheiros pelas 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 numerável a ser copiada.
Observações
Elementos duplicados na coleção enumerável não são copiados para a nova instância da SortedSet<T> classe, e não são lançadas exceções.
Este construtor é uma O(n log n) operação, onde n é 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 utiliza 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 numerável a ser copiada.
- comparer
- IComparer<T>
O comparador padrão a usar 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 a informação necessária 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.
Observações
Este construtor é chamado durante a desserialização para reconstituir um objeto transmitido através de um fluxo.