SortedSet<T> 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 SortedSet<T> 類別的新執行個體。
多載
| 名稱 | Description |
|---|---|
| SortedSet<T>() |
初始化 SortedSet<T> 類別的新執行個體。 |
| SortedSet<T>(IComparer<T>) |
初始化使用指定比較器的類別新實例 SortedSet<T> 。 |
| SortedSet<T>(IEnumerable<T>) |
初始化一個包含從指定可枚舉集合複製元素的類別新實例 SortedSet<T> 。 |
| SortedSet<T>(IEnumerable<T>, IComparer<T>) |
初始化一個包含從指定可枚舉集合複製元素並使用指定比較器的新類別實例 SortedSet<T> 。 |
| SortedSet<T>(SerializationInfo, StreamingContext) |
已淘汰.
初始化包含序列化資料的 SortedSet<T> 類別新實例。 |
備註
這個建構子是一個 O(1) 運算。
SortedSet<T>()
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
初始化 SortedSet<T> 類別的新執行個體。
public:
SortedSet();
public SortedSet();
Public Sub New ()
適用於
SortedSet<T>(IComparer<T>)
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
初始化使用指定比較器的類別新實例 SortedSet<T> 。
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>
用來比較物件的預設比較器。
例外狀況
comparer 是 null。
範例
以下範例定義了一個比較器(ByFileExtension),用來構造一個排序集合,該集合依副檔名排序檔案名稱。 此程式碼範例是本類別更大範例 SortedSet<T> 的一部分。
// 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
適用於
SortedSet<T>(IEnumerable<T>)
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
初始化一個包含從指定可枚舉集合複製元素的類別新實例 SortedSet<T> 。
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>
可列集被複製。
備註
可枚舉集合中的重複元素不會被複製到新的類別實例 SortedSet<T> 中,且不會拋出例外。
此構造子是一個 O(n log n) 運算,其中 n 是參數中的 collection 元素數。
適用於
SortedSet<T>(IEnumerable<T>, IComparer<T>)
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
初始化一個包含從指定可枚舉集合複製元素並使用指定比較器的新類別實例 SortedSet<T> 。
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>
可列集被複製。
- comparer
- IComparer<T>
用來比較物件的預設比較器。
例外狀況
collection 是 null。
適用於
SortedSet<T>(SerializationInfo, StreamingContext)
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
- 來源:
- SortedSet.cs
警告
This API supports obsolete formatter-based serialization. It should not be called or extended by application code.
初始化包含序列化資料的 SortedSet<T> 類別新實例。
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);
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}")>]
new System.Collections.Generic.SortedSet<'T> : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Collections.Generic.SortedSet<'T>
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> 該物件所需資訊的物件。
- context
- StreamingContext
包含與 SortedSet<T> 物件相關聯序列化串流的來源與目的地的結構。
- 屬性
備註
此建構子在反序列化過程中被呼叫,以重建透過串流傳輸的物件。