HashSet<T> 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
값 집합을 나타냅니다.
generic <typename T>
public ref class HashSet : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IReadOnlyCollection<T>, System::Collections::Generic::ISet<T>
generic <typename T>
public ref class HashSet : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IReadOnlyCollection<T>, System::Collections::Generic::IReadOnlySet<T>, System::Collections::Generic::ISet<T>, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
generic <typename T>
public ref class HashSet : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IReadOnlyCollection<T>, System::Collections::Generic::ISet<T>, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
generic <typename T>
public ref class HashSet : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
generic <typename T>
public ref class HashSet : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::ISet<T>, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
generic <typename T>
public ref class HashSet : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::ISet<T>
public class HashSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.ISet<T>
public class HashSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.IReadOnlySet<T>, System.Collections.Generic.ISet<T>, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
public class HashSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.ISet<T>, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Serializable]
public class HashSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Serializable]
public class HashSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.ISet<T>, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Serializable]
public class HashSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.ISet<T>, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
public class HashSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.ISet<T>
type HashSet<'T> = class
interface ICollection<'T>
interface seq<'T>
interface IEnumerable
interface IReadOnlyCollection<'T>
interface ISet<'T>
type HashSet<'T> = class
interface ICollection<'T>
interface seq<'T>
interface IEnumerable
interface IReadOnlyCollection<'T>
interface ISet<'T>
interface IReadOnlySet<'T>
interface IDeserializationCallback
interface ISerializable
type HashSet<'T> = class
interface ICollection<'T>
interface seq<'T>
interface IEnumerable
interface IReadOnlyCollection<'T>
interface ISet<'T>
interface IDeserializationCallback
interface ISerializable
[<System.Serializable>]
type HashSet<'T> = class
interface ICollection<'T>
interface seq<'T>
interface IEnumerable
interface ISerializable
interface IDeserializationCallback
[<System.Serializable>]
type HashSet<'T> = class
interface ISerializable
interface IDeserializationCallback
interface ISet<'T>
interface ICollection<'T>
interface seq<'T>
interface IEnumerable
[<System.Serializable>]
type HashSet<'T> = class
interface ICollection<'T>
interface seq<'T>
interface IEnumerable
interface ISerializable
interface IDeserializationCallback
interface ISet<'T>
interface IReadOnlyCollection<'T>
type HashSet<'T> = class
interface ISet<'T>
interface ICollection<'T>
interface seq<'T>
interface IEnumerable
Public Class HashSet(Of T)
Implements ICollection(Of T), IEnumerable(Of T), IReadOnlyCollection(Of T), ISet(Of T)
Public Class HashSet(Of T)
Implements ICollection(Of T), IDeserializationCallback, IEnumerable(Of T), IReadOnlyCollection(Of T), IReadOnlySet(Of T), ISerializable, ISet(Of T)
Public Class HashSet(Of T)
Implements ICollection(Of T), IDeserializationCallback, IEnumerable(Of T), IReadOnlyCollection(Of T), ISerializable, ISet(Of T)
Public Class HashSet(Of T)
Implements ICollection(Of T), IDeserializationCallback, IEnumerable(Of T), ISerializable
Public Class HashSet(Of T)
Implements ICollection(Of T), IDeserializationCallback, IEnumerable(Of T), ISerializable, ISet(Of T)
Public Class HashSet(Of T)
Implements ICollection(Of T), IEnumerable(Of T), ISet(Of T)
형식 매개 변수
- T
해시 집합에 있는 요소의 형식입니다.
- 상속
-
HashSet<T>
- 특성
- 구현
예제
다음 예제에서는 서로 다른 두 집합을 병합하는 방법을 보여 줍니다. 이 예제에서는 두 HashSet<T> 개의 개체를 만들고 각각 짝수 및 홀수로 채웁니다. 세 번째 HashSet<T> 개체는 짝수를 포함하는 집합에서 만들어집니다. 그런 다음, 메서드를 UnionWith 호출하여 세 번째 집합에 홀수 집합을 추가합니다.
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 }
*/
Imports System.Collections.Generic
Class Program
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
Private Shared Sub DisplaySet(ByVal collection As HashSet(Of Integer))
Console.Write("{")
For Each i As Integer In collection
Console.Write(" {0}", i)
Next i
Console.WriteLine(" }")
End Sub
End Class
' 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 }
설명
이 API에 대한 자세한 내용은 HashSet<T에 대한 추가 API 설명을 참조하세요>.
생성자
HashSet<T>() |
비어 있으며 집합 형식에 대한 기본 같음 비교자를 사용하는 HashSet<T> 클래스의 새 인스턴스를 초기화합니다. |
HashSet<T>(IEnumerable<T>) |
집합 형식에 대한 기본 같음 비교자를 사용하고 지정된 컬렉션에서 복사한 요소가 들어 있으며 복사된 요소 수를 수용하기에 용량이 충분한 HashSet<T> 클래스의 새 인스턴스를 초기화합니다. |
HashSet<T>(IEnumerable<T>, IEqualityComparer<T>) |
집합 형식에 대한 지정된 같음 비교자를 사용하고 지정된 컬렉션에서 복사한 요소가 들어 있으며 복사된 요소 수를 수용하기에 용량이 충분한 HashSet<T> 클래스의 새 인스턴스를 초기화합니다. |
HashSet<T>(IEqualityComparer<T>) |
비어 있으며 집합 형식에 대한 지정된 같음 비교자를 사용하는 HashSet<T> 클래스의 새 인스턴스를 초기화합니다. |
HashSet<T>(Int32) |
비어 있지만 |
HashSet<T>(Int32, IEqualityComparer<T>) |
집합 형식에 대해 지정된 같음 비교자를 사용하고 |
HashSet<T>(SerializationInfo, StreamingContext) |
사용되지 않음.
serialize된 데이터를 사용하여 HashSet<T> 클래스의 새 인스턴스를 초기화합니다. |
속성
Capacity |
값 집합을 나타냅니다. |
Comparer |
집합의 값이 같은지 확인하는 데 사용되는 IEqualityComparer<T> 개체를 가져옵니다. |
Count |
집합에 포함된 요소 수를 가져옵니다. |
메서드
Add(T) |
지정된 요소를 집합에 추가합니다. |
Clear() |
HashSet<T> 개체에서 요소를 모두 제거합니다. |
Contains(T) |
HashSet<T> 개체에 지정된 요소가 포함되어 있는지 확인합니다. |
CopyTo(T[]) |
HashSet<T> 개체의 요소를 배열에 복사합니다. |
CopyTo(T[], Int32) |
지정된 배열 인덱스에서 시작하여 HashSet<T> 개체의 요소를 배열에 복사합니다. |
CopyTo(T[], Int32, Int32) |
지정된 배열 인덱스에서 시작하여 HashSet<T> 개체에서 지정된 수의 요소를 배열에 복사합니다. |
CreateSetComparer() |
HashSet<T> 개체에 대한 같음 테스트에 사용할 수 있는 IEqualityComparer 개체를 반환합니다. |
EnsureCapacity(Int32) |
이 해시 집합이 백업 스토리지의 추가 확장 없이 지정된 수의 요소를 보유할 수 있는지 확인합니다. |
Equals(Object) |
지정된 개체가 현재 개체와 같은지 확인합니다. (다음에서 상속됨 Object) |
ExceptWith(IEnumerable<T>) |
현재 HashSet<T> 개체에서 지정된 컬렉션의 모든 요소를 제거합니다. |
GetEnumerator() |
HashSet<T> 개체에서 반복되는 열거자를 반환합니다. |
GetHashCode() |
기본 해시 함수로 작동합니다. (다음에서 상속됨 Object) |
GetObjectData(SerializationInfo, StreamingContext) |
사용되지 않음.
ISerializable 인터페이스를 구현하고 HashSet<T> 개체를 serialize하는 데 필요한 데이터를 반환합니다. |
GetType() |
현재 인스턴스의 Type을 가져옵니다. (다음에서 상속됨 Object) |
IntersectWith(IEnumerable<T>) |
현재 HashSet<T> 개체를 수정하여 해당 개체와 지정된 컬렉션에 동시에 있는 요소만 포함합니다. |
IsProperSubsetOf(IEnumerable<T>) |
HashSet<T> 개체가 지정된 컬렉션의 진 부분 집합인지 확인합니다. |
IsProperSupersetOf(IEnumerable<T>) |
HashSet<T> 개체가 지정된 컬렉션의 진 상위 집합인지 확인합니다. |
IsSubsetOf(IEnumerable<T>) |
HashSet<T> 개체가 지정된 컬렉션의 하위 집합인지 확인합니다. |
IsSupersetOf(IEnumerable<T>) |
HashSet<T> 개체가 지정된 컬렉션의 상위 집합인지 확인합니다. |
MemberwiseClone() |
현재 Object의 단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
OnDeserialization(Object) |
ISerializable 인터페이스를 구현하고, deserialization이 완료되면 deserialization 이벤트를 발생시킵니다. |
Overlaps(IEnumerable<T>) |
현재 HashSet<T> 개체와 지정된 컬렉션이 공통 요소를 공유하는지 여부를 확인합니다. |
Remove(T) |
HashSet<T> 개체에서 지정된 요소를 제거합니다. |
RemoveWhere(Predicate<T>) |
HashSet<T> 컬렉션에서 지정된 조건자에 정의된 조건과 일치하는 요소를 모두 제거합니다. |
SetEquals(IEnumerable<T>) |
HashSet<T> 개체와 지정된 컬렉션에 같은 요소가 들어 있는지 확인합니다. |
SymmetricExceptWith(IEnumerable<T>) |
현재 HashSet<T> 개체를 수정하여 해당 개체와 지정된 컬렉션 중 하나에만 있는 요소만 포함합니다. |
ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |
TrimExcess() |
HashSet<T> 개체의 용량을 실제로 포함된 요소 수로 설정하고 구현별로 다른 근방 값으로 올림합니다. |
TrimExcess(Int32) |
값 집합을 나타냅니다. |
TryGetValue(T, T) |
집합에서 지정된 값을 검색하여 동일한 값을 찾은 경우 해당 값을 반환합니다. |
UnionWith(IEnumerable<T>) |
현재 HashSet<T> 개체를 수정하여 해당 개체와 지정된 컬렉션에 있는 모든 요소를 포함시킵니다. |
명시적 인터페이스 구현
ICollection<T>.Add(T) |
ICollection<T> 개체에 항목을 추가합니다. |
ICollection<T>.IsReadOnly |
컬렉션이 읽기 전용인지 여부를 나타내는 값을 가져옵니다. |
IEnumerable.GetEnumerator() |
컬렉션을 반복하는 열거자를 반환합니다. |
IEnumerable<T>.GetEnumerator() |
컬렉션을 반복하는 열거자를 반환합니다. |
확장 메서드
적용 대상
추가 정보
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기