# ValenceSet<T> class

Namespace: [Grasshopper2.Collections](https://developer.rhino3d.com/api/gh2/namespace/grasshopper2.collections.md) · Assembly: [Grasshopper2](https://developer.rhino3d.com/api/gh2/assembly/grasshopper2.md)

```cs
public sealed class ValenceSet<T> : IEnumerable<(T value, int valence)>
```

Provides a hashset like type which also stores valences for entries. This collection is thread-safe for adding and removing, but not for enumerating.

**Type parameters:**

- `T`

## Constructors

- [ValenceSet<T>](https://developer.rhino3d.com/api/gh2/type/grasshopper2.collections.valenceset-1/ctor.md): (3 overloads) Creates a valence set with the default comparer.

## Properties

- [AllValues](https://developer.rhino3d.com/api/gh2/type/grasshopper2.collections.valenceset-1/allvalues.md): Iterate over all values. This iteration re-duplicates based on valence.
- [Count](https://developer.rhino3d.com/api/gh2/type/grasshopper2.collections.valenceset-1/count.md): Gets the number of values in this set, including all duplicate ones. This property is not thread safe and should not be used while Add or Remove methods are liable to be invoked from different threads.
- [DistinctCount](https://developer.rhino3d.com/api/gh2/type/grasshopper2.collections.valenceset-1/distinctcount.md): Gets the number of distinct values in this set.
- [DistinctValues](https://developer.rhino3d.com/api/gh2/type/grasshopper2.collections.valenceset-1/distinctvalues.md): Iterate over all distinct values.
- [HighestValence](https://developer.rhino3d.com/api/gh2/type/grasshopper2.collections.valenceset-1/highestvalence.md): Gets the highest valence in this set. This property is not thread safe and should not be used while Add or Remove methods are liable to be invoked from different threads.
- [LowestValence](https://developer.rhino3d.com/api/gh2/type/grasshopper2.collections.valenceset-1/lowestvalence.md): Gets the lowest valence in this set. This property is not thread safe and should not be used while Add or Remove methods are liable to be invoked from different threads.

## Methods

- [Add](https://developer.rhino3d.com/api/gh2/type/grasshopper2.collections.valenceset-1/add.md): (2 overloads) Add a new value with a custom valence to this set.
- [Clear](https://developer.rhino3d.com/api/gh2/type/grasshopper2.collections.valenceset-1/clear.md): Clear the entire set.
- [Contains](https://developer.rhino3d.com/api/gh2/type/grasshopper2.collections.valenceset-1/contains.md): Gets whether the given value is contained within this set.
- [GetEnumerator](https://developer.rhino3d.com/api/gh2/type/grasshopper2.collections.valenceset-1/getenumerator.md): Enumerate over all values and their associated valences in this set. This method is not thread safe and should not be used while Add or Remove methods are liable to be invoked from different threads.
- [Remove](https://developer.rhino3d.com/api/gh2/type/grasshopper2.collections.valenceset-1/remove.md): (2 overloads) Remove a value with a custom valence from this set.
- [RemoveAll](https://developer.rhino3d.com/api/gh2/type/grasshopper2.collections.valenceset-1/removeall.md): Remove all values from this set.
- [IEnumerable.GetEnumerator](https://developer.rhino3d.com/api/gh2/type/grasshopper2.collections.valenceset-1/system-collections-ienumerable-getenumerator.md)
- [Valence](https://developer.rhino3d.com/api/gh2/type/grasshopper2.collections.valenceset-1/valence.md): Gets the valence of the given value. If the value is not part of this set, zero is returned.

## Operators

- [operator +](https://developer.rhino3d.com/api/gh2/type/grasshopper2.collections.valenceset-1/op-addition.md): (static) Merge two sets.
