BiDictionaryDuplicateValuePolicy Enum
Definition
Specifies how a BiDictionary<TKey, TValue> responds when an add or assignment operation supplies a value that is already bound to a different key.
public enum BiDictionaryDuplicateValuePolicy
- Extension Methods
Fields
Throw = 0Binding a value already held by a different key is rejected: Add(TKey, TValue) and the indexer setter throw ArgumentException, while TryAdd(TKey, TValue) returns false without modifying state. This is the default and matches the semantics of Guava's
BiMap.put.Replace = 1Binding a value already held by a different key silently evicts the previous binding - the key that held the value is removed along with its entry - so the new pair wins and the mapping stays one-to-one. This matches the semantics of Guava's
BiMap.forcePut.
Remarks
A BiDictionary<TKey, TValue> maintains a strict one-to-one mapping: every key maps to exactly one value and every value maps back to exactly one key. The policy is consulted whenever a mutation would bind a value that a different key already holds - re-assigning the same value to the same key is never a conflict.
The policy is fixed at construction and applies symmetrically through the Inverse view: because keys and values swap roles in the inverse, the policy there governs conflicts on what the original dictionary considers its keys. In both directions the invariant being protected is the same - the mapping stays one-to-one.
Applies to
| Product | Versions |
|---|---|
| .NET | 8, 10 |