Class ObservableHashSet<T>
Inherited Members
Namespace: DevToys.Api
Assembly: DevToys.Api.dll
Syntax
public class ObservableHashSet<T> : ISet<T>, ICollection<T>, IReadOnlyCollection<T>, IEnumerable<T>, IEnumerable, INotifyCollectionChanged, INotifyPropertyChanged, INotifyPropertyChanging
Type Parameters
Name | Description |
---|---|
T | The type of elements in the hash set. |
Remarks
See Local views of tracked entities in EF Core for more information and examples.
Constructors
ObservableHashSet()
Initializes a new instance of the ObservableHashSet<T> class that is empty and uses the default equality comparer for the set type.
Declaration
public ObservableHashSet()
ObservableHashSet(IEnumerable<T>)
Initializes a new instance of the ObservableHashSet<T> class that uses the default equality comparer for the set type, contains elements copied from the specified collection, and has sufficient capacity to accommodate the number of elements copied.
Declaration
public ObservableHashSet(IEnumerable<T> collection)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | collection | The collection whose elements are copied to the new set. |
ObservableHashSet(IEnumerable<T>, IEqualityComparer<T>)
Initializes a new instance of the ObservableHashSet<T> class that uses the specified equality comparer for the set type, contains elements copied from the specified collection, and has sufficient capacity to accommodate the number of elements copied.
Declaration
public ObservableHashSet(IEnumerable<T> collection, IEqualityComparer<T> comparer)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | collection | The collection whose elements are copied to the new set. |
IEqualityComparer<T> | comparer | The IEqualityComparer<T> implementation to use when comparing values in the set, or null to use the default IEqualityComparer<T> implementation for the set type. |
ObservableHashSet(IEqualityComparer<T>)
Initializes a new instance of the ObservableHashSet<T> class that is empty and uses the specified equality comparer for the set type.
Declaration
public ObservableHashSet(IEqualityComparer<T> comparer)
Parameters
Type | Name | Description |
---|---|---|
IEqualityComparer<T> | comparer | The IEqualityComparer<T> implementation to use when comparing values in the set, or null to use the default IEqualityComparer<T> implementation for the set type. |
Properties
Comparer
Gets the IEqualityComparer<T> object that is used to determine equality for the values in the set.
Declaration
public virtual IEqualityComparer<T> Comparer { get; }
Property Value
Type | Description |
---|---|
IEqualityComparer<T> |
Count
Gets the number of elements that are contained in the hash set.
Declaration
public virtual int Count { get; }
Property Value
Type | Description |
---|---|
int |
IsReadOnly
Gets a value indicating whether the hash set is read-only.
Declaration
public virtual bool IsReadOnly { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
Add(T)
Adds the specified element to the hash set.
Declaration
public virtual bool Add(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The element to add to the set. |
Returns
Type | Description |
---|---|
bool | true if the element is added to the hash set; false if the element is already present. |
Clear()
Removes all elements from the hash set.
Declaration
public virtual void Clear()
Contains(T)
Determines whether the hash set object contains the specified element.
Declaration
public virtual bool Contains(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The element to locate in the hash set. |
Returns
Type | Description |
---|---|
bool | true if the hash set contains the specified element; otherwise, false. |
CopyTo(T[])
Copies the elements of the hash set to an array.
Declaration
public virtual void CopyTo(T[] array)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The one-dimensional array that is the destination of the elements copied from the hash set. The array must have zero-based indexing. |
CopyTo(T[], int)
Copies the elements of the hash set to an array, starting at the specified array index.
Declaration
public virtual void CopyTo(T[] array, int arrayIndex)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The one-dimensional array that is the destination of the elements copied from the hash set. The array must have zero-based indexing. |
int | arrayIndex | The zero-based index in array at which copying begins. |
CopyTo(T[], int, int)
Copies the specified number of elements of the hash set to an array, starting at the specified array index.
Declaration
public virtual void CopyTo(T[] array, int arrayIndex, int count)
Parameters
Type | Name | Description |
---|---|---|
T[] | array | The one-dimensional array that is the destination of the elements copied from the hash set. The array must have zero-based indexing. |
int | arrayIndex | The zero-based index in array at which copying begins. |
int | count | The number of elements to copy to array. |
ExceptWith(IEnumerable<T>)
Removes all elements in the specified collection from the hash set.
Declaration
public virtual void ExceptWith(IEnumerable<T> other)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | other | The collection of items to remove from the current hash set. |
GetEnumerator()
Returns an enumerator that iterates through the hash set.
Declaration
public virtual HashSet<T>.Enumerator GetEnumerator()
Returns
Type | Description |
---|---|
HashSet<T>.Enumerator | An enumerator for the hash set. |
IntersectWith(IEnumerable<T>)
Modifies the current hash set to contain only elements that are present in that object and in the specified collection.
Declaration
public virtual void IntersectWith(IEnumerable<T> other)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | other | The collection to compare to the current hash set. |
IsProperSubsetOf(IEnumerable<T>)
Determines whether the hash set is a proper subset of the specified collection.
Declaration
public virtual bool IsProperSubsetOf(IEnumerable<T> other)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | other | The collection to compare to the current hash set. |
Returns
Type | Description |
---|---|
bool | true if the hash set is a proper subset of other; otherwise, false. |
IsProperSupersetOf(IEnumerable<T>)
Determines whether the hash set is a proper superset of the specified collection.
Declaration
public virtual bool IsProperSupersetOf(IEnumerable<T> other)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | other | The collection to compare to the current hash set. |
Returns
Type | Description |
---|---|
bool | true if the hash set is a proper superset of other; otherwise, false. |
IsSubsetOf(IEnumerable<T>)
Determines whether the hash set is a subset of the specified collection.
Declaration
public virtual bool IsSubsetOf(IEnumerable<T> other)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | other | The collection to compare to the current hash set. |
Returns
Type | Description |
---|---|
bool | true if the hash set is a subset of other; otherwise, false. |
IsSupersetOf(IEnumerable<T>)
Determines whether the hash set is a superset of the specified collection.
Declaration
public virtual bool IsSupersetOf(IEnumerable<T> other)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | other | The collection to compare to the current hash set. |
Returns
Type | Description |
---|---|
bool | true if the hash set is a superset of other; otherwise, false. |
OnCollectionChanged(NotifyCollectionChangedEventArgs)
Raises the CollectionChanged event.
Declaration
protected virtual void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
NotifyCollectionChangedEventArgs | e | Details of the change. |
OnPropertyChanged(PropertyChangedEventArgs)
Raises the PropertyChanged event.
Declaration
protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
PropertyChangedEventArgs | e | Details of the property that changed. |
OnPropertyChanging(PropertyChangingEventArgs)
Raises the PropertyChanging event.
Declaration
protected virtual void OnPropertyChanging(PropertyChangingEventArgs e)
Parameters
Type | Name | Description |
---|---|---|
PropertyChangingEventArgs | e | Details of the property that is changing. |
Overlaps(IEnumerable<T>)
Determines whether the current System.Collections.Generic.HashSet`1 object and a specified collection share common elements.
Declaration
public virtual bool Overlaps(IEnumerable<T> other)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | other | The collection to compare to the current hash set. |
Returns
Type | Description |
---|---|
bool | true if the hash set and other share at least one common element; otherwise, false. |
Remove(T)
Removes the specified element from the hash set.
Declaration
public virtual bool Remove(T item)
Parameters
Type | Name | Description |
---|---|---|
T | item | The element to remove. |
Returns
Type | Description |
---|---|
bool | true if the element is successfully found and removed; otherwise, false. |
RemoveWhere(Predicate<T>)
Removes all elements that match the conditions defined by the specified predicate from the hash set.
Declaration
public virtual int RemoveWhere(Predicate<T> match)
Parameters
Type | Name | Description |
---|---|---|
Predicate<T> | match | The Predicate<T> delegate that defines the conditions of the elements to remove. |
Returns
Type | Description |
---|---|
int | The number of elements that were removed from the hash set. |
SetEquals(IEnumerable<T>)
Determines whether the hash set and the specified collection contain the same elements.
Declaration
public virtual bool SetEquals(IEnumerable<T> other)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | other | The collection to compare to the current hash set. |
Returns
Type | Description |
---|---|
bool |
SymmetricExceptWith(IEnumerable<T>)
Modifies the current hash set to contain only elements that are present either in that object or in the specified collection, but not both.
Declaration
public virtual void SymmetricExceptWith(IEnumerable<T> other)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | other | The collection to compare to the current hash set. |
TrimExcess()
Sets the capacity of the hash set to the actual number of elements it contains, rounded up to a nearby, implementation-specific value.
Declaration
public virtual void TrimExcess()
UnionWith(IEnumerable<T>)
Modifies the hash set to contain all elements that are present in itself, the specified collection, or both.
Declaration
public virtual void UnionWith(IEnumerable<T> other)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<T> | other | The collection to compare to the current hash set. |
Events
CollectionChanged
Occurs when the contents of the hash set changes.
Declaration
public event NotifyCollectionChangedEventHandler? CollectionChanged
Event Type
Type | Description |
---|---|
NotifyCollectionChangedEventHandler |
PropertyChanged
Occurs when a property of this hash set (such as Count) changes.
Declaration
public event PropertyChangedEventHandler? PropertyChanged
Event Type
Type | Description |
---|---|
PropertyChangedEventHandler |
PropertyChanging
Occurs when a property of this hash set (such as Count) is changing.
Declaration
public event PropertyChangingEventHandler? PropertyChanging
Event Type
Type | Description |
---|---|
PropertyChangingEventHandler |