Microsoft.Bcl.HashCode
6.0.0
Prefix Reserved
dotnet add package Microsoft.Bcl.HashCode --version 6.0.0
NuGet\Install-Package Microsoft.Bcl.HashCode -Version 6.0.0
<PackageReference Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
<PackageReference Include="Microsoft.Bcl.HashCode" />
paket add Microsoft.Bcl.HashCode --version 6.0.0
#r "nuget: Microsoft.Bcl.HashCode, 6.0.0"
#addin nuget:?package=Microsoft.Bcl.HashCode&version=6.0.0
#tool nuget:?package=Microsoft.Bcl.HashCode&version=6.0.0
About
Provides the HashCode type for .NET Standard 2.0. This package is not required starting with .NET Standard 2.1 and .NET Core 3.0.
The HashCode type is shipped as part of the shared framework starting with .NET 5.
Key Features
The HashCode type offered in this assembly combines the hash code for multiple values into a single hash code.
How to Use
The static methods in this class combine the default hash codes of up to eight values.
using System;
using System.Collections.Generic;
public struct OrderOrderLine : IEquatable<OrderOrderLine>
{
public int OrderId { get; }
public int OrderLineId { get; }
public OrderOrderLine(int orderId, int orderLineId) => (OrderId, OrderLineId) = (orderId, orderLineId);
public override bool Equals(object obj) => obj is OrderOrderLine o && Equals(o);
public bool Equals(OrderOrderLine other) => OrderId == other.OrderId && OrderLineId == other.OrderLineId;
public override int GetHashCode() => HashCode.Combine(OrderId, OrderLineId);
}
class Program
{
static void Main(string[] args)
{
var set = new HashSet<OrderOrderLine>
{
new OrderOrderLine(1, 1),
new OrderOrderLine(1, 1),
new OrderOrderLine(1, 2)
};
Console.WriteLine($"Item count: {set.Count}.");
}
}
// The example displays the following output:
// Item count: 2.
The instance methods in this class combine the hash codes of more than eight values.
using System;
using System.Collections.Generic;
public struct Path : IEquatable<Path>
{
public IReadOnlyList<string> Segments { get; }
public Path(params string[] segments) => Segments = segments;
public override bool Equals(object obj) => obj is Path o && Equals(o);
public bool Equals(Path other)
{
if (ReferenceEquals(Segments, other.Segments)) return true;
if (Segments is null || other.Segments is null) return false;
if (Segments.Count != other.Segments.Count) return false;
for (var i = 0; i < Segments.Count; i++)
{
if (!string.Equals(Segments[i], other.Segments[i]))
return false;
}
return true;
}
public override int GetHashCode()
{
var hash = new HashCode();
for (var i = 0; i < Segments?.Count; i++)
hash.Add(Segments[i]);
return hash.ToHashCode();
}
}
class Program
{
static void Main(string[] args)
{
var set = new HashSet<Path>
{
new Path("C:", "tmp", "file.txt"),
new Path("C:", "tmp", "file.txt"),
new Path("C:", "tmp", "file.tmp")
};
Console.WriteLine($"Item count: {set.Count}.");
}
}
// The example displays the following output:
// Item count: 2.
The instance methods also combine the hash codes produced by a specific IEqualityComparer<T> implementation.
using System;
using System.Collections.Generic;
public struct Path : IEquatable<Path>
{
public IReadOnlyList<string> Segments { get; }
public Path(params string[] segments) => Segments = segments;
public override bool Equals(object obj) => obj is Path o && Equals(o);
public bool Equals(Path other)
{
if (ReferenceEquals(Segments, other.Segments)) return true;
if (Segments is null || other.Segments is null) return false;
if (Segments.Count != other.Segments.Count) return false;
for (var i = 0; i < Segments.Count; i++)
{
if (!string.Equals(Segments[i], other.Segments[i], StringComparison.OrdinalIgnoreCase))
return false;
}
return true;
}
public override int GetHashCode()
{
var hash = new HashCode();
for (var i = 0; i < Segments?.Count; i++)
hash.Add(Segments[i], StringComparer.OrdinalIgnoreCase);
return hash.ToHashCode();
}
}
class Program
{
static void Main(string[] args)
{
var set = new HashSet<Path>
{
new Path("C:", "tmp", "file.txt"),
new Path("C:", "TMP", "file.txt"),
new Path("C:", "tmp", "FILE.TXT")
};
Console.WriteLine($"Item count: {set.Count}.");
}
}
// The example displays the following output:
// Item count: 1.
The HashCode structure must be passed by-reference to other methods, as it is a value type.
using System;
using System.Collections.Generic;
public struct Path : IEquatable<Path>
{
public IReadOnlyList<string> Segments { get; }
public Path(params string[] segments) => Segments = segments;
public override bool Equals(object obj) => obj is Path o && Equals(o);
public bool Equals(Path other)
{
if (ReferenceEquals(Segments, other.Segments)) return true;
if (Segments is null || other.Segments is null) return false;
if (Segments.Count != other.Segments.Count) return false;
for (var i = 0; i < Segments.Count; i++)
{
if (!PlatformUtils.PathEquals(Segments[i], other.Segments[i]))
return false;
}
return true;
}
public override int GetHashCode()
{
var hash = new HashCode();
for (var i = 0; i < Segments?.Count; i++)
PlatformUtils.AddPath(ref hash, Segments[i]);
return hash.ToHashCode();
}
}
internal static class PlatformUtils
{
public static bool PathEquals(string a, string b) => string.Equals(a, b, StringComparison.OrdinalIgnoreCase);
public static void AddPath(ref HashCode hash, string path) => hash.Add(path, StringComparer.OrdinalIgnoreCase);
}
class Program
{
static void Main(string[] args)
{
var set = new HashSet<Path>
{
new Path("C:", "tmp", "file.txt"),
new Path("C:", "TMP", "file.txt"),
new Path("C:", "tmp", "FILE.TXT")
};
Console.WriteLine($"Item count: {set.Count}.");
}
}
// The example displays the following output:
// Item count: 1.
Main Types
The main types provided by this library are:
- System.HashCode
Additional Documentation
- Security design doc for System.HashCode
- API reference can be found in: https://learn.microsoft.com/en-us/dotnet/api/system.hashcode
License
Microsoft.Bcl.HashCode is released as open source under the MIT license.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- No dependencies.
-
.NETStandard 2.0
- No dependencies.
-
.NETStandard 2.1
- No dependencies.
-
net6.0
- No dependencies.
NuGet packages (648)
Showing the top 5 NuGet packages that depend on Microsoft.Bcl.HashCode:
Package | Downloads |
---|---|
CsvHelper
A library for reading and writing CSV files. Extremely fast, flexible, and easy to use. Supports reading and writing of custom class objects. |
|
AutoFixture
AutoFixture makes it easier for developers to do Test-Driven Development by automating non-relevant Test Fixture Setup, allowing the Test Developer to focus on the essentials of each test case. |
|
Microsoft.Azure.Cosmos
This client library enables client applications to connect to Azure Cosmos DB via the NoSQL API. Azure Cosmos DB is a globally distributed, multi-model database service. For more information, refer to http://azure.microsoft.com/services/cosmos-db/. |
|
ClosedXML
See release notes https://github.com/ClosedXML/ClosedXML/releases/tag/0.105.0-rc ClosedXML is a .NET library for reading, manipulating and writing Excel 2007+ (.xlsx, .xlsm) files. It aims to provide an intuitive and user-friendly interface to dealing with the underlying OpenXML API. |
|
HotChocolate.Language.SyntaxTree
This package contains the abstract syntax tree that is used by the Hot Chocolate parsers. |
GitHub repositories (115)
Showing the top 20 popular GitHub repositories that depend on Microsoft.Bcl.HashCode:
Repository | Stars |
---|---|
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
|
|
dotnet/runtime
.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
|
|
chocolatey/choco
Chocolatey - the package manager for Windows
|
|
felixse/FluentTerminal
A Terminal Emulator based on UWP and web technologies.
|
|
dotnet/machinelearning
ML.NET is an open source and cross-platform machine learning framework for .NET.
|
|
ChilliCream/graphql-platform
Welcome to the home of the Hot Chocolate GraphQL server for .NET, the Strawberry Shake GraphQL client for .NET and Nitro the awesome Monaco based GraphQL IDE.
|
|
ClosedXML/ClosedXML
ClosedXML is a .NET library for reading, manipulating and writing Excel 2007+ (.xlsx, .xlsm) files. It aims to provide an intuitive and user-friendly interface to dealing with the underlying OpenXML API.
|
|
JoshClose/CsvHelper
Library to help reading and writing CSV files
|
|
openiddict/openiddict-core
Flexible and versatile OAuth 2.0/OpenID Connect stack for .NET
|
|
dotnet/Silk.NET
The high-speed OpenGL, OpenCL, OpenAL, OpenXR, GLFW, SDL, Vulkan, Assimp, WebGPU, and DirectX bindings library your mother warned you about.
|
|
UnigramDev/Unigram
Telegram for Windows
|
|
Richasy/Bili.Copilot
B站第三方 Windows 桌面客户端,使用 Windows App SDK 构建的原生应用
|
|
BililiveRecorder/BililiveRecorder
录播姬 | mikufans 生放送录制
|
|
testcontainers/testcontainers-dotnet
A library to support tests with throwaway instances of Docker containers for all compatible .NET Standard versions.
|
|
ravendb/ravendb
ACID Document Database
|
|
elastic/elasticsearch-net
This strongly-typed, client library enables working with Elasticsearch. It is the official client maintained and supported by Elastic.
|
|
CommunityToolkit/dotnet
.NET Community Toolkit is a collection of helpers and APIs that work for all .NET developers and are agnostic of any specific UI platform. The toolkit is maintained and published by Microsoft, and part of the .NET Foundation.
|
|
linq2db/linq2db
Linq to database provider.
|
|
dotnet/interactive
.NET Interactive combines the power of .NET with many other languages to create notebooks, REPLs, and embedded coding experiences. Share code, explore data, write, and learn across your apps in ways you couldn't before.
|
|
OpenTabletDriver/OpenTabletDriver
Open source, cross-platform, user-mode tablet driver
|
Version | Downloads | Last updated |
---|---|---|
6.0.0 | 1,091,618 | 11/12/2024 |
1.1.1 | 86,941,645 | 1/12/2021 |
1.1.0 | 223,524,534 | 12/3/2019 |
1.1.0-preview3.19551.4 | 162,077 | 11/13/2019 |
1.1.0-preview2.19523.17 | 31,651 | 11/1/2019 |
1.1.0-preview1.19504.10 | 795 | 10/15/2019 |
1.0.0 | 13,783,276 | 9/23/2019 |
1.0.0-rc1.19456.4 | 1,695 | 9/16/2019 |
1.0.0-preview9.19421.4 | 808 | 9/4/2019 |
1.0.0-preview9.19416.11 | 716 | 9/4/2019 |
1.0.0-preview8.19405.3 | 11,889 | 8/13/2019 |
1.0.0-preview7.19362.9 | 1,973 | 7/23/2019 |
1.0.0-preview6.19303.8 | 56,408 | 6/12/2019 |
1.0.0-preview6.19264.9 | 667 | 9/4/2019 |
1.0.0-preview6.19259.10 | 2,858 | 5/10/2019 |