gethashcode Questions

3

Solved

To quote from Guidelines and rules for GetHashCode by Eric Lippert: Rule: Consumers of GetHashCode cannot rely upon it being stable over time or across appdomains Suppose you have a Customer ...
Levinson asked 1/3, 2011 at 13:14

5

Solved

I get the following exception while inserting an object with hibernate. Reading from the database works like a charm. I use MySQL 5.5 as database provider and hibernate 3.6.5. I have the following...
Charactery asked 19/7, 2011 at 8:44

2

Solved

Consider the following code: Console.WriteLine("Hello, World!".GetHashCode()); First run: 139068974 Second run: -263623806 Now consider the same thing written in Kotlin: println(&quo...
Kensell asked 11/10, 2022 at 5:29

7

Solved

How does the default implementation for GetHashCode() work? And does it handle structures, classes, arrays, etc. efficiently and well enough? I am trying to decide in what cases I should pack my o...
Subjectivism asked 6/4, 2009 at 3:25

4

EnumerableObject : IEnumerable<Foo> wraps a List<Foo> If EnumerableObject a.SequenceEquals( EnumerableObject b), then they are equal. Therefore, a GetHashCode must be implemented. Th...
Torch asked 11/11, 2011 at 13:49

22

Solved

In .NET, the GetHashCode method is used in a lot of places throughout the .NET base class libraries. Implementing it properly is especially important to find items quickly in a collection or when d...
Anthropomorphosis asked 4/11, 2008 at 20:53

4

Solved

This is kind of an academic point, but I feel I don't fully understand hash codes if I don't understand why this is recommended by books such as Effective Java and many SO questions. Suppose: publi...
Manno asked 19/11, 2012 at 15:20

7

Solved

I'm working with a domain model and was thinking about the various ways that we have to implement these two methods in .NET. What is your preferred strategy? This is my current implementation: pu...
Vittoria asked 2/3, 2010 at 12:46

2

Solved

Why is GetHashCode() returning a different value for the same string? I can't describe how to duplicate this, but trust that this is not a practical joke and that the two following lines came from ...
Corundum asked 16/12, 2010 at 22:47

6

Solved

Being somewhat lazy about implementing lots of IEqualityComparers, and given that I couldn't easily edit class implementations of the objects being compared, I went with the following, meant to be ...
Cloister asked 6/5, 2011 at 9:15

1

Solved

.NET Standard 2.1 / .NET Core 3 introduce System.HashCode to quickly combine fields and values to a hash code without having to care about the underlying implementation. However, it only provides C...
Subtrahend asked 17/12, 2019 at 13:18

4

Solved

What is the best way to create your own GetHashCode method for a class in C#? Suppose I have a simple class (which overrides the Equals method), as follows: class Test { public string[] names; ...
Excretion asked 22/7, 2009 at 15:32

6

Solved

A glance at the source code for string.GetHashCode using Reflector reveals the following (for mscorlib.dll version 4.0): public override unsafe int GetHashCode() { fixed (char* str = ((char*) thi...
Advance asked 16/6, 2010 at 13:37

1

In the implementation of GetHashCode below, when Collection is null or empty will both result in a hash code of 0. A colleague suggested return a random hard coded number like 19 to differentiate...
Interne asked 12/6, 2019 at 7:50

5

Solved

Ok, before you get all mad because there are hundreds of similar sounding questions posted on the internet, I can assure you that I have just spent the last few hours reading all of them and have n...
Hoxha asked 31/10, 2013 at 15:4

2

Solved

I recently discovered that Visual Studio 2017 can auto-generate overrides for Equals and GetHashCode, but I was wondering why the GetHashCode implementation is not in an unchecked block? I made a ...
Vainglory asked 15/2, 2019 at 15:40

4

Solved

I'm attempting to write a method to generate an integer based on any given string. When calling this method on 2 identical strings, I need the method to generate the same exact integer both times. ...
Lavender asked 11/11, 2014 at 17:0

3

There are many questions and answers and articles to this question available but in my opinion there seems to be no real clear/correct answer For me Ayende has the best generic implementation so f...
Bigelow asked 29/6, 2012 at 13:31

3

Solved

I'm implementing IEquatable<T>, and I am having difficulty finding consensus on the GetHashCode override on a mutable class. The following resources all provide an implementation where GetHa...
Tisman asked 1/3, 2018 at 17:43

4

Solved

String.GetHashCode's behavior is depend on the program architecture. So it will return one value in x86 and one value on x64. I have a test application which must run in x86 and it must predict the...
Stere asked 1/12, 2011 at 23:1

2

Solved

How do I deal with null fields in GetHashCode function? Module Module1 Sub Main() Dim c As New Contact Dim hash = c.GetHashCode End Sub Public Class Contact : Implements IEquatable(Of Contac...
Dactylography asked 15/3, 2010 at 2:27

1

Solved

For a Delphi project (built with RAD Studio XE7), I want to create a dictionary of brushes. Each dictionary item contains a TMyBrush object as key, that describes the brush to retrieve, and a GDI+ ...
Eleaseeleatic asked 10/12, 2016 at 13:26

3

Solved

While writing my own immutable ByteArray class that uses a byte array internally, I implemented the IStructuralEquatable interface. In my implementation I delegated the task of calculating hash cod...
Adahadaha asked 29/7, 2012 at 23:55

4

Solved

In search of a fast composite key for Dictionary I came upon anomaly I cannot understand nor justify. In limited testing Dictionary<KeyValuePair<UInt32, UInt32>, string> is signif...
Spatula asked 29/9, 2012 at 23:16

1

Solved

The Help says this: Anonymous types are class types that derive directly from object, and that cannot be cast to any type except object. The compiler provides a name for each anonymous type, a...
Micmac asked 25/7, 2016 at 2:11

© 2022 - 2024 — McMap. All rights reserved.