budul.HashExtensions 3.0.0

dotnet add package budul.HashExtensions --version 3.0.0
                    
NuGet\Install-Package budul.HashExtensions -Version 3.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="budul.HashExtensions" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="budul.HashExtensions" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="budul.HashExtensions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add budul.HashExtensions --version 3.0.0
                    
#r "nuget: budul.HashExtensions, 3.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package budul.HashExtensions@3.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=budul.HashExtensions&version=3.0.0
                    
Install as a Cake Addin
#tool nuget:?package=budul.HashExtensions&version=3.0.0
                    
Install as a Cake Tool

HashExtensions

License NuGet

HashExtensions is a C# library providing flexible and efficient hashing utilities for sequences, collections, and strings. It targets .NET 10.

Features

  • Sequence Hashing: Compute hashes for sequences, collections, or arrays, with support for:
    • Order-sensitive, order-insensitive, and direction-insensitive hashing
    • Hashing based on specific properties or multiple properties
  • Static Hash Generation: Generate fixed-length numeric or alphanumeric hashes from strings or collections of strings. The results are stable across processes, machines, and runs
  • Customizable Hash Length: Control the length of generated hashes (1 to 12 digits/characters)
  • Optimized Performance: Single enumeration, span-based hashing, and allocation-free hashing of short strings

Installation

dotnet add package budul.HashExtensions

Usage

Sequence Hashing

Sequence hashes are based on System.HashCode. They are consistent within a process, but not stable across processes. Do not persist them.

using HashExtensions;

// Hash a sequence of objects
int hash = Extensions.GetSequenceHash(item1, item2, item3);

// Hash a collection with a property selector
int hash = myList.GetSequenceHash(x => x.Id);

// Hash a collection with multiple property selectors
int hash = myList.GetSequenceHash(x => x.Id, x => x.Name);

// Order-insensitive hash (items do not need to be comparable)
int hash = myList.GetSequenceHashOrdered();

// Direction-insensitive hash
int hash = myList.GetSequenceHashDirected();

Static Hash Generation

Static hashes are derived from SHA-256 and always return the same result for the same input.

using HashExtensions;

// Numeric hash from strings
ulong numHash = Extensions.GetStaticHashNumber("foo", "bar");

// Alphanumeric hash from strings
string textHash = Extensions.GetStaticHashText("foo", "bar");

// Control hash length (1 to 12)
ulong shortHash = "example".GetStaticHashNumber(length: 6);
string shortTextHash = "example".GetStaticHashText(length: 8);

Collections of strings are hashed value by value, including the length of each value. ["a\nb"] and ["a", "b"] therefore produce different hashes. Null and empty inputs result in 0 (numeric) or an empty string (text).

API Reference

See HashExtensions/Extensions.cs for full documentation and XML comments.

Target Frameworks

  • .NET 10

Migration to 3.0

  • Only .NET 10 is supported. Older target frameworks (.NET Standard 2.1, .NET 6/7/8) were dropped.
  • The values of GetStaticHashNumber and GetStaticHashText changed (new hash derivation and collection hashing). Re-calculate stored hashes.
  • GetSequenceHash<T>(params Func<T, object>[]) was removed. It hashed the delegates, not the values.
  • GetSequenceHashOrdered no longer requires comparable items.

License

MIT

Contributing

Contributions, issues, and feature requests are welcome!

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.0 60 11/29/2026
2.0.0 309 8/23/2025
1.8.0 843 10/30/2020
1.7.0 693 10/16/2020
1.6.0 5,911 10/11/2020
1.5.0 671 9/30/2020
1.4.0 712 9/23/2020
1.3.0 663 8/7/2020
1.2.0 673 7/29/2020
1.1.0 767 6/24/2020
1.0.0 2,280 5/5/2020