SortedSet<T> 建構函式

定義

初始化 SortedSet<T> 類別的新執行個體。Initializes a new instance of the SortedSet<T> class.

多載

SortedSet<T>()

初始化 SortedSet<T> 類別的新執行個體。Initializes a new instance of the SortedSet<T> class.

SortedSet<T>(IComparer<T>)

初始化 SortedSet<T> 類別的新執行個體,這個執行個體使用指定的比較子。Initializes a new instance of the SortedSet<T> class that uses a specified comparer.

SortedSet<T>(IEnumerable<T>)

初始化 SortedSet<T> 類別的新執行個體,這個執行個體包含從指定的可列舉集合複製的項目。Initializes a new instance of the SortedSet<T> class that contains elements copied from a specified enumerable collection.

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

初始化 SortedSet<T> 類別的新執行個體,這個執行個體包含從指定的可列舉集合複製的項目,而且使用指定的比較子。Initializes a new instance of the SortedSet<T> class that contains elements copied from a specified enumerable collection and that uses a specified comparer.

SortedSet<T>(SerializationInfo, StreamingContext)

初始化 SortedSet<T> 類別的新執行個體,這個執行個體包含序列化資料。Initializes a new instance of the SortedSet<T> class that contains serialized data.

備註

這個函式是一項作業 O(1)This constructor is an O(1) operation.

SortedSet<T>()

初始化 SortedSet<T> 類別的新執行個體。Initializes a new instance of the SortedSet<T> class.

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

適用於

SortedSet<T>(IComparer<T>)

初始化 SortedSet<T> 類別的新執行個體,這個執行個體使用指定的比較子。Initializes a new instance of the SortedSet<T> class that uses a specified comparer.

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

參數

comparer
IComparer<T>

用來比較物件的預設比較子。The default comparer to use for comparing objects.

例外狀況

comparernullcomparer is null.

範例

下列範例會定義比較子 (ByFileExtension) ,用來建立依副檔名排序檔案名的已排序集合。The following example defines a comparer (ByFileExtension) that is used to construct a sorted set that sorts file names by their extensions. 這個程式碼範例是針對類別提供之較大範例的一部分 SortedSet<T>This code example is part of a larger example provided for the SortedSet<T> class.

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

備註

如果 comparer 未執行 IComparable<T> ,您必須指定 IComparer<T> 要使用的物件。If comparer does not implement IComparable<T>, you must specify an IComparer<T> object to be used.

適用於

SortedSet<T>(IEnumerable<T>)

初始化 SortedSet<T> 類別的新執行個體,這個執行個體包含從指定的可列舉集合複製的項目。Initializes a new instance of the SortedSet<T> class that contains elements copied from a specified enumerable collection.

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

參數

collection
IEnumerable<T>

要複製的可列舉集合。The enumerable collection to be copied.

備註

可列舉集合中重複的元素不會複製到類別的新實例 SortedSet<T> ,也不會擲回例外狀況。Duplicate elements in the enumerable collection are not copied into the new instance of the SortedSet<T> class, and no exceptions are thrown.

這個函式是一 O(n log n) 項作業,其中 n 是參數中的元素數目 collectionThis constructor is an O(n log n) operation, where n is the number of elements in the collection parameter.

適用於

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

初始化 SortedSet<T> 類別的新執行個體,這個執行個體包含從指定的可列舉集合複製的項目,而且使用指定的比較子。Initializes a new instance of the SortedSet<T> class that contains elements copied from a specified enumerable collection and that uses a specified 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);
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))

參數

collection
IEnumerable<T>

要複製的可列舉集合。The enumerable collection to be copied.

comparer
IComparer<T>

用來比較物件的預設比較子。The default comparer to use for comparing objects.

例外狀況

collectionnullcollection is null.

適用於

SortedSet<T>(SerializationInfo, StreamingContext)

初始化 SortedSet<T> 類別的新執行個體,這個執行個體包含序列化資料。Initializes a new instance of the SortedSet<T> class that contains serialized data.

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)

參數

info
SerializationInfo

物件,包含序列化 SortedSet<T> 物件所需的資訊。The object that contains the information that is required to serialize the SortedSet<T> object.

context
StreamingContext

結構,包含與 SortedSet<T> 物件關聯的序列化資料流的來源和目的端。The structure that contains the source and destination of the serialized stream associated with the SortedSet<T> object.

備註

這個函式會在還原序列化期間呼叫,以重新構成透過資料流程傳輸的物件。This constructor is called during deserialization to reconstitute an object that is transmitted over a stream.

適用於