Class HashCodeHelper
- Namespace
- Existential
- Assembly
- Existential.Net.dll
Provides a method to calculate hash codes from provided values. A hash code can be generated for any type of object by passing its fields as arguments to this method.
public static class HashCodeHelper
- Inheritance
-
System.ObjectHashCodeHelper
- Inherited Members
-
System.Object.Equals(System.Object)System.Object.Equals(System.Object, System.Object)System.Object.GetHashCode()System.Object.GetType()System.Object.MemberwiseClone()System.Object.ReferenceEquals(System.Object, System.Object)System.Object.ToString()
Methods
CalculateHashCode(Object[])
Generates a hash code from the provided values. A hash code can be generated for any type of object, by passing its fields as arguments to this method. This method calculates a hash code by combining the hash codes of the provided objects.
The order of the objects matters, meaning that providing the same objects in a different order will result in a different hash code. If no objects are provided, the method returns 0. If any of the provided objects are null, they are ignored when calculating the hash code.
public static int CalculateHashCode(params object[] inObjectArray)
Parameters
inObjectArray
System.Object[]An array of values from which to calculate a hash code.
Returns
- System.Int32
A hash code generated from the provided values.
Remarks
This method is a modification of a method documented on Stack Overflow by Jon Skeet, which in turn is derived from the FNV (Fowler/Noll/Vo) hash algorithm . This method differs in that it uses a randomly assigned number as the offset basis. Doing so means that a hash value for the same object will be different when calculated in a different process. This behaviour is a better match for default hash code behaviour as of .NET 5.0 (and optional behaviour that can be enabled in the .NET Framework by enabling the use of the randomised string hash algorithm ).