Aracılığıyla paylaş


HashSet<T> Oluşturucular

Tanım

HashSet<T> sınıfının yeni bir örneğini başlatır.

Aşırı Yüklemeler

Name Description
HashSet<T>()

Boş sınıfın HashSet<T> yeni bir örneğini başlatır ve küme türü için varsayılan eşitlik karşılaştırıcısını kullanır.

HashSet<T>(IEnumerable<T>)

Küme türü için varsayılan eşitlik karşılaştırıcısını kullanan, belirtilen koleksiyondan kopyalanan öğeleri içeren ve kopyalanan öğe sayısını karşılamak için yeterli kapasiteye sahip olan sınıfın yeni bir örneğini HashSet<T> başlatır.

HashSet<T>(IEqualityComparer<T>)

Boş olan sınıfın HashSet<T> yeni bir örneğini başlatır ve küme türü için belirtilen eşitlik karşılaştırıcısını kullanır.

HashSet<T>(Int32)

Sınıfın HashSet<T> boş, ancak öğeler için capacity ayrılmış alanı olan yeni bir örneğini başlatır ve küme türü için varsayılan eşitlik karşılaştırıcısını kullanır.

HashSet<T>(IEnumerable<T>, IEqualityComparer<T>)

Küme türü için belirtilen eşitlik karşılaştırıcısını kullanan, belirtilen koleksiyondan kopyalanan öğeleri içeren ve kopyalanan öğe sayısını karşılamak için yeterli kapasiteye sahip olan sınıfın yeni bir örneğini HashSet<T> başlatır.

HashSet<T>(Int32, IEqualityComparer<T>)

Küme türü için belirtilen eşitlik karşılaştırıcısını kullanan ve öğeleri barındırmak capacity için yeterli kapasiteye sahip olan sınıfın yeni bir örneğini HashSet<T> başlatır.

HashSet<T>(SerializationInfo, StreamingContext)
Geçersiz.

Serileştirilmiş verilerle HashSet<T> sınıfının yeni bir örneğini başlatır.

HashSet<T>()

Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs

Boş sınıfın HashSet<T> yeni bir örneğini başlatır ve küme türü için varsayılan eşitlik karşılaştırıcısını kullanır.

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

Örnekler

Aşağıdaki örnekte iki HashSet<T> nesnenin nasıl oluşturulacağı ve doldurulacağı gösterilmektedir. Bu örnek, yöntemi için UnionWith sağlanan daha büyük bir örneğin parçasıdır.

HashSet<int> evenNumbers = new HashSet<int>();
HashSet<int> oddNumbers = new HashSet<int>();

for (int i = 0; i < 5; i++)
{
    // Populate numbers with just even numbers.
    evenNumbers.Add(i * 2);

    // Populate oddNumbers with just odd numbers.
    oddNumbers.Add((i * 2) + 1);
}
let evenNumbers = HashSet<int>()
let oddNumbers = HashSet<int>()

for i = 0 to 4 do
    // Populate numbers with just even numbers.
    evenNumbers.Add(i * 2) |> ignore

    // Populate oddNumbers with just odd numbers.
    oddNumbers.Add(i * 2 + 1) |> ignore
Dim evenNumbers As HashSet(Of Integer) = New HashSet(Of Integer)()
Dim oddNumbers As HashSet(Of Integer) = New HashSet(Of Integer)()

For i As Integer = 0 To 4

    ' Populate evenNumbers with only even numbers.
    evenNumbers.Add(i * 2)

    ' Populate oddNumbers with only odd numbers.
    oddNumbers.Add((i * 2) + 1)
Next i

Açıklamalar

Bir HashSet<T> nesnenin kapasitesi, nesnenin barındırabileceği öğe sayısıdır. HashSet<T> Nesneye öğeler eklendikçe nesnenin kapasitesi otomatik olarak artar.

Bu oluşturucu bir O(1) işlemidir.

Şunlara uygulanır

HashSet<T>(IEnumerable<T>)

Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs

Küme türü için varsayılan eşitlik karşılaştırıcısını kullanan, belirtilen koleksiyondan kopyalanan öğeleri içeren ve kopyalanan öğe sayısını karşılamak için yeterli kapasiteye sahip olan sınıfın yeni bir örneğini HashSet<T> başlatır.

public:
 HashSet(System::Collections::Generic::IEnumerable<T> ^ collection);
public HashSet(System.Collections.Generic.IEnumerable<T> collection);
new System.Collections.Generic.HashSet<'T> : seq<'T> -> System.Collections.Generic.HashSet<'T>
Public Sub New (collection As IEnumerable(Of T))

Parametreler

collection
IEnumerable<T>

Öğeleri yeni kümeye kopyalanan koleksiyon.

Özel durumlar

collection, null'e eşittir.

Örnekler

Aşağıdaki örnekte, mevcut bir HashSet<T> kümeden nasıl koleksiyon oluşturulacağı gösterilmektedir. Bu örnekte, sırasıyla çift ve tek tamsayılarla iki küme oluşturulur. Ardından çift tamsayı kümesinden üçüncü HashSet<T> bir nesne oluşturulur.

HashSet<int> evenNumbers = new HashSet<int>();
HashSet<int> oddNumbers = new HashSet<int>();

for (int i = 0; i < 5; i++)
{
    // Populate numbers with just even numbers.
    evenNumbers.Add(i * 2);

    // Populate oddNumbers with just odd numbers.
    oddNumbers.Add((i * 2) + 1);
}

Console.Write("evenNumbers contains {0} elements: ", evenNumbers.Count);
DisplaySet(evenNumbers);

Console.Write("oddNumbers contains {0} elements: ", oddNumbers.Count);
DisplaySet(oddNumbers);

// Create a new HashSet populated with even numbers.
HashSet<int> numbers = new HashSet<int>(evenNumbers);
Console.WriteLine("numbers UnionWith oddNumbers...");
numbers.UnionWith(oddNumbers);

Console.Write("numbers contains {0} elements: ", numbers.Count);
DisplaySet(numbers);

void DisplaySet(HashSet<int> collection)
{
    Console.Write("{");
    foreach (int i in collection)
    {
        Console.Write(" {0}", i);
    }
    Console.WriteLine(" }");
}

/* This example produces output similar to the following:
* evenNumbers contains 5 elements: { 0 2 4 6 8 }
* oddNumbers contains 5 elements: { 1 3 5 7 9 }
* numbers UnionWith oddNumbers...
* numbers contains 10 elements: { 0 2 4 6 8 1 3 5 7 9 }
*/

let displaySet (collection: HashSet<int>) =
    printf "{"

    for i in collection do
        printf $" {i}"

    printfn " }"

let evenNumbers = HashSet<int>()
let oddNumbers = HashSet<int>()

for i = 0 to 4 do
    // Populate numbers with just even numbers.
    evenNumbers.Add(i * 2) |> ignore

    // Populate oddNumbers with just odd numbers.
    oddNumbers.Add(i * 2 + 1) |> ignore

printf $"evenNumbers contains {evenNumbers.Count} elements: "
displaySet evenNumbers

printf $"oddNumbers contains {oddNumbers.Count} elements: "
displaySet oddNumbers

// Create a new HashSet populated with even numbers.
let numbers = HashSet<int> evenNumbers
printfn "numbers UnionWith oddNumbers..."
numbers.UnionWith oddNumbers

printf $"numbers contains {numbers.Count} elements: "
displaySet numbers
// This example produces output similar to the following:
//    evenNumbers contains 5 elements: { 0 2 4 6 8 }
//    oddNumbers contains 5 elements: { 1 3 5 7 9 }
//    numbers UnionWith oddNumbers...
//    numbers contains 10 elements: { 0 2 4 6 8 1 3 5 7 9 }
Shared Sub Main()

    Dim evenNumbers As HashSet(Of Integer) = New HashSet(Of Integer)()
    Dim oddNumbers As HashSet(Of Integer) = New HashSet(Of Integer)()

    For i As Integer = 0 To 4

        ' Populate evenNumbers with only even numbers.
        evenNumbers.Add(i * 2)

        ' Populate oddNumbers with only odd numbers.
        oddNumbers.Add((i * 2) + 1)
    Next i

    Console.Write("evenNumbers contains {0} elements: ", evenNumbers.Count)
    DisplaySet(evenNumbers)

    Console.Write("oddNumbers contains {0} elements: ", oddNumbers.Count)
    DisplaySet(oddNumbers)

    ' Create a new HashSet populated with even numbers.
    Dim numbers As HashSet(Of Integer) = New HashSet(Of Integer)(evenNumbers)
    Console.WriteLine("numbers UnionWith oddNumbers...")
    numbers.UnionWith(oddNumbers)

    Console.Write("numbers contains {0} elements: ", numbers.Count)
    DisplaySet(numbers)
End Sub

Açıklamalar

Bir HashSet<T> nesnenin kapasitesi, nesnenin barındırabileceği öğe sayısıdır. HashSet<T> Nesneye öğeler eklendikçe nesnenin kapasitesi otomatik olarak artar.

collection Yinelemeler içeriyorsa, küme her benzersiz öğeden birini içerir. Özel durum oluşturulmayacak. Bu nedenle, sonuçta elde edilen kümenin boyutu boyutuyla collectionaynı değildir.

Bu oluşturucu, parametredeki collection öğelerin sayısı olan n bir O(n) işlemidir.

Şunlara uygulanır

HashSet<T>(IEqualityComparer<T>)

Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs

Boş olan sınıfın HashSet<T> yeni bir örneğini başlatır ve küme türü için belirtilen eşitlik karşılaştırıcısını kullanır.

public:
 HashSet(System::Collections::Generic::IEqualityComparer<T> ^ comparer);
public HashSet(System.Collections.Generic.IEqualityComparer<T> comparer);
public HashSet(System.Collections.Generic.IEqualityComparer<T>? comparer);
new System.Collections.Generic.HashSet<'T> : System.Collections.Generic.IEqualityComparer<'T> -> System.Collections.Generic.HashSet<'T>
Public Sub New (comparer As IEqualityComparer(Of T))

Parametreler

comparer
IEqualityComparer<T>

Kümedeki IEqualityComparer<T> değerleri karşılaştırırken veya null küme türü için varsayılan EqualityComparer<T> uygulamayı kullanırken kullanılacak uygulama.

Açıklamalar

Bir HashSet<T> nesnenin kapasitesi, nesnenin barındırabileceği öğe sayısıdır. HashSet<T> Nesneye öğeler eklendikçe nesnenin kapasitesi otomatik olarak artar.

Bu oluşturucu bir O(1) işlemidir.

Şunlara uygulanır

HashSet<T>(Int32)

Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs

Sınıfın HashSet<T> boş, ancak öğeler için capacity ayrılmış alanı olan yeni bir örneğini başlatır ve küme türü için varsayılan eşitlik karşılaştırıcısını kullanır.

public:
 HashSet(int capacity);
public HashSet(int capacity);
new System.Collections.Generic.HashSet<'T> : int -> System.Collections.Generic.HashSet<'T>
Public Sub New (capacity As Integer)

Parametreler

capacity
Int32

öğesinin HashSet<T>ilk boyutu.

Açıklamalar

Yeniden boyutlandırmalar görece pahalı olduğundan (yeniden vurgulama gerektirir), bu, değerini temel alarak ilk kapasiteyi ayarlayarak yeniden boyutlandırma gereksinimini en aza indirmeye capacityçalışır.

Dikkat

Kullanıcı girişinden geliyorsa capacity , parametresiz capacity bir oluşturucu aşırı yüklemesi kullanmayı tercih edin ve öğeler eklendikçe koleksiyonun yeniden boyutlandırılmalarını sağlayın. Kullanıcı tarafından belirtilen bir değer kullanmanız gerekiyorsa, bunu makul bir sınıra (örneğin, Math.Clamp(untrustedValue, 0, 20)) sıkıştırın veya öğe sayısının belirtilen değerle eşleşip eşleşmediğini doğrulayın.

Şunlara uygulanır

HashSet<T>(IEnumerable<T>, IEqualityComparer<T>)

Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs

Küme türü için belirtilen eşitlik karşılaştırıcısını kullanan, belirtilen koleksiyondan kopyalanan öğeleri içeren ve kopyalanan öğe sayısını karşılamak için yeterli kapasiteye sahip olan sınıfın yeni bir örneğini HashSet<T> başlatır.

public:
 HashSet(System::Collections::Generic::IEnumerable<T> ^ collection, System::Collections::Generic::IEqualityComparer<T> ^ comparer);
public HashSet(System.Collections.Generic.IEnumerable<T> collection, System.Collections.Generic.IEqualityComparer<T> comparer);
public HashSet(System.Collections.Generic.IEnumerable<T> collection, System.Collections.Generic.IEqualityComparer<T>? comparer);
new System.Collections.Generic.HashSet<'T> : seq<'T> * System.Collections.Generic.IEqualityComparer<'T> -> System.Collections.Generic.HashSet<'T>
Public Sub New (collection As IEnumerable(Of T), comparer As IEqualityComparer(Of T))

Parametreler

collection
IEnumerable<T>

Öğeleri yeni kümeye kopyalanan koleksiyon.

comparer
IEqualityComparer<T>

Kümedeki IEqualityComparer<T> değerleri karşılaştırırken veya null küme türü için varsayılan EqualityComparer<T> uygulamayı kullanırken kullanılacak uygulama.

Özel durumlar

collection, null'e eşittir.

Örnekler

Aşağıdaki örnekte, araç türleri koleksiyonunun öğeleri üzerinde büyük/küçük harfe duyarlı olmayan karşılaştırmalara izin vermek için sağlanan IEqualityComparer<T> bir HashSet<T> kullanılır.

HashSet<string> allVehicles = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
List<string> someVehicles = new List<string>();

someVehicles.Add("Planes");
someVehicles.Add("Trains");
someVehicles.Add("Automobiles");

// Add in the vehicles contained in the someVehicles list.
allVehicles.UnionWith(someVehicles);

Console.WriteLine("The current HashSet contains:\n");
foreach (string vehicle in allVehicles)
{
    Console.WriteLine(vehicle);
}

allVehicles.Add("Ships");
allVehicles.Add("Motorcycles");
allVehicles.Add("Rockets");
allVehicles.Add("Helicopters");
allVehicles.Add("Submarines");

Console.WriteLine("\nThe updated HashSet contains:\n");
foreach (string vehicle in allVehicles)
{
    Console.WriteLine(vehicle);
}

// Verify that the 'All Vehicles' set contains at least the vehicles in
// the 'Some Vehicles' list.
if (allVehicles.IsSupersetOf(someVehicles))
{
    Console.Write("\nThe 'All' vehicles set contains everything in ");
    Console.WriteLine("'Some' vechicles list.");
}

// Check for Rockets. Here the OrdinalIgnoreCase comparer will compare
// true for the mixed-case vehicle type.
if (allVehicles.Contains("roCKeTs"))
{
    Console.WriteLine("\nThe 'All' vehicles set contains 'roCKeTs'");
}

allVehicles.ExceptWith(someVehicles);
Console.WriteLine("\nThe excepted HashSet contains:\n");
foreach (string vehicle in allVehicles)
{
    Console.WriteLine(vehicle);
}

// Remove all the vehicles that are not 'super cool'.
allVehicles.RemoveWhere(isNotSuperCool);

Console.WriteLine("\nThe super cool vehicles are:\n");
foreach (string vehicle in allVehicles)
{
    Console.WriteLine(vehicle);
}

// Predicate to determine vehicle 'coolness'.
bool isNotSuperCool(string vehicle)
{
    bool superCool = (vehicle == "Helicopters") || (vehicle == "Motorcycles");

    return !superCool;
}

// The program writes the following output to the console.
//
// The current HashSet contains:
//
// Planes
// Trains
// Automobiles
//
// The updated HashSet contains:
//
// Planes
// Trains
// Automobiles
// Ships
// Motorcycles
// Rockets
// Helicopters
// Submarines
//
// The 'All' vehicles set contains everything in 'Some' vechicles list.
//
// The 'All' vehicles set contains 'roCKeTs'
//
// The excepted HashSet contains:
//
// Ships
// Motorcycles
// Rockets
// Helicopters
// Submarines
//
// The super cool vehicles are:
//
// Motorcycles
// Helicopters
let allVehicles = HashSet<string> StringComparer.OrdinalIgnoreCase
let someVehicles = ResizeArray()

someVehicles.Add "Planes"
someVehicles.Add "Trains"
someVehicles.Add "Automobiles"

// Add in the vehicles contained in the someVehicles list.
allVehicles.UnionWith someVehicles

printfn "The current HashSet contains:\n"

for vehicle in allVehicles do
    printfn $"{vehicle}"

allVehicles.Add "Ships" |> ignore
allVehicles.Add "Motorcycles" |> ignore
allVehicles.Add "Rockets" |> ignore
allVehicles.Add "Helicopters" |> ignore
allVehicles.Add "Submarines" |> ignore

printfn "\nThe updated HashSet contains:\n"

for vehicle in allVehicles do
    printfn $"{vehicle}"

// Verify that the 'All Vehicles' set contains at least the vehicles in
// the 'Some Vehicles' list.
if allVehicles.IsSupersetOf someVehicles then
    printfn "\nThe 'All' vehicles set contains everything in 'Some' vehicles list."

// Check for Rockets. Here the OrdinalIgnoreCase comparer will compare
// true for the mixed-case vehicle type.
if allVehicles.Contains "roCKeTs" then
    printfn "\nThe 'All' vehicles set contains 'roCKeTs'"

allVehicles.ExceptWith someVehicles
printfn "\nThe excepted HashSet contains:\n"

for vehicle in allVehicles do
    printfn $"{vehicle}"

// Predicate to determine vehicle 'coolness'.
let isNotSuperCool vehicle =
    let superCool = vehicle = "Helicopters" || vehicle = "Motorcycles"
    not superCool

// Remove all the vehicles that are not 'super cool'.
allVehicles.RemoveWhere isNotSuperCool |> ignore

printfn "\nThe super cool vehicles are:\n"

for vehicle in allVehicles do
    printfn $"{vehicle}"

// The program writes the following output to the console.
//
// The current HashSet contains:
//
// Planes
// Trains
// Automobiles
//
// The updated HashSet contains:
//
// Planes
// Trains
// Automobiles
// Ships
// Motorcycles
// Rockets
// Helicopters
// Submarines
//
// The 'All' vehicles set contains everything in 'Some' vehicles list.
//
// The 'All' vehicles set contains 'roCKeTs'
//
// The excepted HashSet contains:
//
// Ships
// Motorcycles
// Rockets
// Helicopters
// Submarines
//
// The super cool vehicles are:
//
// Motorcycles
// Helicopters
Imports System.Collections.Generic

Class Program
    Public Shared Sub Main()
        Dim allVehicles As New HashSet(Of String)(StringComparer.OrdinalIgnoreCase)
        Dim someVehicles As New List(Of String)()

        someVehicles.Add("Planes")
        someVehicles.Add("Trains")
        someVehicles.Add("Automobiles")

        ' Add in the vehicles contained in the someVehicles list.
        allVehicles.UnionWith(someVehicles)

        Console.WriteLine("The current HashSet contains:" + Environment.NewLine)
        For Each vehicle As String In allVehicles
            Console.WriteLine(vehicle)
        Next vehicle

        allVehicles.Add("Ships")
        allVehicles.Add("Motorcycles")
        allVehicles.Add("Rockets")
        allVehicles.Add("Helicopters")
        allVehicles.Add("Submarines")

        Console.WriteLine(Environment.NewLine + "The updated HashSet contains:" + Environment.NewLine)
        For Each vehicle As String In allVehicles
            Console.WriteLine(vehicle)
        Next vehicle

        ' Verify that the 'All Vehicles' set contains at least the vehicles in
        ' the 'Some Vehicles' list.
        If allVehicles.IsSupersetOf(someVehicles) Then
            Console.Write(Environment.NewLine + "The 'All' vehicles set contains everything in ")
            Console.WriteLine("'Some' vechicles list.")
        End If

        ' Check for Rockets. Here the OrdinalIgnoreCase comparer will compare
        ' True for the mixed-case vehicle type.
        If allVehicles.Contains("roCKeTs") Then
            Console.WriteLine(Environment.NewLine + "The 'All' vehicles set contains 'roCKeTs'")
        End If

        allVehicles.ExceptWith(someVehicles)
        Console.WriteLine(Environment.NewLine + "The excepted HashSet contains:" + Environment.NewLine)
        For Each vehicle As String In allVehicles
            Console.WriteLine(vehicle)
        Next vehicle

        ' Remove all the vehicles that are not 'super cool'.
        allVehicles.RemoveWhere(AddressOf isNotSuperCool)

        Console.WriteLine(Environment.NewLine + "The super cool vehicles are:" + Environment.NewLine)
        For Each vehicle As String In allVehicles
            Console.WriteLine(vehicle)
        Next vehicle
    End Sub

    ' Predicate to determine vehicle 'coolness'.
    Private Shared Function isNotSuperCool(vehicle As String) As Boolean
        Dim notSuperCool As Boolean = _
            (vehicle <> "Helicopters") And (vehicle <> "Motorcycles")

        Return notSuperCool
    End Function
End Class

'
' The program writes the following output to the console.
'
' The current HashSet contains:
'
' Planes
' Trains
' Automobiles
'
' The updated HashSet contains:
'
' Planes
' Trains
' Automobiles
' Ships
' Motorcycles
' Rockets
' Helicopters
' Submarines
'
' The 'All' vehicles set contains everything in 'Some' vechicles list.
'
' The 'All' vehicles set contains 'roCKeTs'
'
' The excepted HashSet contains:
'
' Ships
' Motorcycles
' Rockets
' Helicopters
' Submarines
'
' The super cool vehicles are:
'
' Motorcycles
' Helicopters

Açıklamalar

Bir HashSet<T> nesnenin kapasitesi, nesnenin barındırabileceği öğe sayısıdır. HashSet<T> Nesneye öğeler eklendikçe nesnenin kapasitesi otomatik olarak artar.

collection Yinelemeler içeriyorsa, küme her benzersiz öğeden birini içerir. Özel durum oluşturulmayacak. Bu nedenle, sonuçta elde edilen kümenin boyutu boyutuyla collectionaynı değildir.

Bu oluşturucu, parametredeki collection öğelerin sayısı olan n bir O(n) işlemidir.

Şunlara uygulanır

HashSet<T>(Int32, IEqualityComparer<T>)

Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs

Küme türü için belirtilen eşitlik karşılaştırıcısını kullanan ve öğeleri barındırmak capacity için yeterli kapasiteye sahip olan sınıfın yeni bir örneğini HashSet<T> başlatır.

public:
 HashSet(int capacity, System::Collections::Generic::IEqualityComparer<T> ^ comparer);
public HashSet(int capacity, System.Collections.Generic.IEqualityComparer<T>? comparer);
public HashSet(int capacity, System.Collections.Generic.IEqualityComparer<T> comparer);
new System.Collections.Generic.HashSet<'T> : int * System.Collections.Generic.IEqualityComparer<'T> -> System.Collections.Generic.HashSet<'T>
Public Sub New (capacity As Integer, comparer As IEqualityComparer(Of T))

Parametreler

capacity
Int32

öğesinin HashSet<T>ilk boyutu.

comparer
IEqualityComparer<T>

IEqualityComparer<T> Kümedeki değerleri karşılaştırırken kullanılacak uygulama veya küme türü için varsayılan IEqualityComparer<T> uygulamayı kullanmak üzere null (Visual Basic'te hiçbir şey).

Açıklamalar

Yeniden boyutlandırmalar görece pahalı olduğundan (yeniden vurgulama gerektirir), bu, değerini temel alarak ilk kapasiteyi ayarlayarak yeniden boyutlandırma gereksinimini en aza indirmeye capacityçalışır.

Dikkat

Kullanıcı girişinden geliyorsa capacity , parametresiz capacity bir oluşturucu aşırı yüklemesi kullanmayı tercih edin ve öğeler eklendikçe koleksiyonun yeniden boyutlandırılmalarını sağlayın. Kullanıcı tarafından belirtilen bir değer kullanmanız gerekiyorsa, bunu makul bir sınıra (örneğin, Math.Clamp(untrustedValue, 0, 20)) sıkıştırın veya öğe sayısının belirtilen değerle eşleşip eşleşmediğini doğrulayın.

Şunlara uygulanır

HashSet<T>(SerializationInfo, StreamingContext)

Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs
Kaynak:
HashSet.cs

Dikkat

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

Serileştirilmiş verilerle HashSet<T> sınıfının yeni bir örneğini başlatır.

protected:
 HashSet(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 HashSet(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
protected HashSet(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.HashSet<'T> : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Collections.Generic.HashSet<'T>
new System.Collections.Generic.HashSet<'T> : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Collections.Generic.HashSet<'T>
Protected Sub New (info As SerializationInfo, context As StreamingContext)

Parametreler

info
SerializationInfo

SerializationInfo Nesneyi serileştirmek HashSet<T> için gereken bilgileri içeren bir nesne.

context
StreamingContext

StreamingContext Nesneyle ilişkilendirilmiş serileştirilmiş akışın kaynağını ve hedefini HashSet<T> içeren bir yapı.

Öznitelikler

Açıklamalar

Bu oluşturucu, bir akış üzerinden iletilen bir nesneyi yeniden oluşturmak için seri durumdan çıkarma sırasında çağrılır. Daha fazla bilgi için bkz. XML ve SOAP Serileştirme.

Şunlara uygulanır