SortedSet<T> Construtores
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Inicializa uma nova instância da classe SortedSet<T>.
Sobrecargas
| SortedSet<T>() |
Inicializa uma nova instância da classe SortedSet<T>. |
| SortedSet<T>(IComparer<T>) |
Inicializa uma nova instância da classe SortedSet<T> que usa um comparador especificado. |
| SortedSet<T>(IEnumerable<T>) |
Inicializa uma nova instância da classe SortedSet<T> que contém elementos copiados de uma coleção enumerável especificada. |
| SortedSet<T>(IEnumerable<T>, IComparer<T>) |
Inicializa uma nova instância da classe SortedSet<T> que contém elementos copiados de uma coleção enumerável especificada e que usa um comparador especificado. |
| SortedSet<T>(SerializationInfo, StreamingContext) |
Obsoleto.
Inicializa uma nova instância da classe SortedSet<T> que contém dados serializados. |
Comentários
Esse construtor é uma O(1) operação.
SortedSet<T>()
- Origem:
- SortedSet.cs
- Origem:
- SortedSet.cs
- Origem:
- SortedSet.cs
Inicializa uma nova instância da classe SortedSet<T>.
public:
SortedSet();
public SortedSet ();
Public Sub New ()
Aplica-se a
SortedSet<T>(IComparer<T>)
- Origem:
- SortedSet.cs
- Origem:
- SortedSet.cs
- Origem:
- SortedSet.cs
Inicializa uma nova instância da classe SortedSet<T> que usa um comparador especificado.
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))
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>)
- Origem:
- SortedSet.cs
- Origem:
- SortedSet.cs
- Origem:
- SortedSet.cs
Inicializa uma nova instância da classe SortedSet<T> 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, em que n é o número de elementos no collection parâmetro .
Aplica-se a
SortedSet<T>(IEnumerable<T>, IComparer<T>)
- Origem:
- SortedSet.cs
- Origem:
- SortedSet.cs
- Origem:
- SortedSet.cs
Inicializa uma nova instância da classe SortedSet<T> 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);
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)
- Origem:
- SortedSet.cs
- Origem:
- SortedSet.cs
- Origem:
- SortedSet.cs
Cuidado
This API supports obsolete formatter-based serialization. It should not be called or extended by application code.
Inicializa uma nova instância da classe SortedSet<T> 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);
[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)
Parâmetros
- info
- SerializationInfo
O objeto que contém as informações necessárias para serializar o objeto SortedSet<T>.
- context
- StreamingContext
A estrutura que contém a origem e o destino do fluxo serializado associado ao objeto SortedSet<T>.
- Atributos
Comentários
Esse construtor é chamado durante a desserialização para reconstituir um objeto que é transmitido por um fluxo.