gethashcode Questions

1

Solved

This question follows on the answer given by Jon Skeet on the question: "What is the best algorithm for an overridden System.Object.GetHashCode?". To calculate the hash code the following algorithm...
Sunflower asked 9/7, 2016 at 10:28

2

Solved

Attempt #3 to simplify this question: A generic List<T> can contain any type - value or reference. When checking to see if a list contains an object, .Contains() uses the default EqualityComp...
Binnings asked 15/5, 2016 at 21:11

7

Solved

Testing the Equals method is pretty much straight forward (as far as I know). But how on earth do you test the GetHashCode method?
Neilneila asked 8/11, 2009 at 15:34

1

Solved

I want to generate an integer hashcode for strings, that will stay constant forever; i.e. the same string should always result in the same hashcode. The hash does not have to be cryptographi...
Logicize asked 25/4, 2016 at 15:53

1

Solved

I was wondering how exactly they generate a hashcode from boolean types in C#/.NET?
Pridemore asked 2/4, 2016 at 14:40

7

Solved

So I'm trying to figure out how to correctly override GetHashCode() in VB for a large number of custom objects. A bit of searching leads me to this wonderful answer. Except there's one problem: VB...
Fulllength asked 11/1, 2011 at 4:37

1

Solved

I have a struct that overrides the Equals() method and the compiler complains about GetHashCode() not being overridden. My struct: private struct Key { ... public override int GetHashC...
Seagraves asked 10/9, 2015 at 12:40

11

Solved

Is there a way of getting a unique identifier of an instance? GetHashCode() is the same for the two references pointing to the same instance. However, two different instances can (quite easily) ge...
Maidie asked 15/4, 2009 at 9:39

1

Solved

System.Drawing.Point has a really, really bad GetHashCode method if you intend to use it to describes 'pixels' in a Image/Bitmap: it is just XOR between the X and Y coordinates. So for a image wit...
Sherburne asked 26/5, 2015 at 21:12

3

Solved

I'm trying to understand the role of the GetHashCode method of the interface IEqualityComparer. The following example is taken from MSDN: using System; using System.Collections.Generic; class Exa...
Interlace asked 4/11, 2010 at 9:43

1

I have two clients that create IPAddress instances from the same byte[] and send it to the server over WCF (using DataContractSerializer). On the server, these IPAddress instances are inserted as ...
Allseed asked 11/2, 2015 at 17:33

9

Solved

After reading all the questions and answers on StackOverflow concerning overriding GetHashCode() I wrote the following extension method for easy and convenient overriding of GetHashCode(): public ...
Adrianneadriano asked 18/4, 2009 at 16:34

1

Solved

I'm reading Effective C# and there is a comment about Object.GetHashCode() that I didn't understand: Object.GetHashCode() uses an internal field in the System.Object class to generate the hash v...
Camembert asked 28/11, 2014 at 20:53

3

Solved

I need a seed for an instance of C#'s Random class, and I read that most people use the current time's ticks counter for this. But that is a 64-bit value and the seed needs to be a 32-bit value. No...
Ratiocinate asked 30/10, 2010 at 22:31

7

Solved

I have an enum public enum INFLOW_SEARCH_ON { ON_ENTITY_HANDLE = 0, ON_LABEL = 1, ON_NODE_HANDLE = 2 } // enum INFLOW_SEARCH_ON I have to use this enum for searching in a grid column. To...
Haematocryal asked 3/1, 2011 at 13:1

3

Solved

I have two related questions: the bitwise operator >>> means that we are shifting the binary number by those many places while filling 0 in the Most Significant Bit. But, then why does the follow...
Idealist asked 28/10, 2013 at 8:6

2

Solved

What would be the best (most elegant or performing) way of overloading the equality operator on a class containing only string attributes? Example: class MagicClass { public string FirstAttribut...
Miki asked 28/4, 2014 at 11:51

7

Solved

My understanding is that you're typically supposed to use xor with GetHashCode() to produce an int to identify your data by its value (as opposed to by its reference). Here's a simple example: clas...
Cruce asked 17/6, 2009 at 17:58

5

Solved

HashSet<T>.Add first compares the results of GetHashCode. If those are equal, it calls Equals. Now, my understanding is in order to implement GetHashCode, something must be done with the fie...
Bismuthinite asked 10/6, 2011 at 10:53

8

Solved

Is it ok to call GetHashCode as a method to test equality from inside the Equals override? For example, is this code acceptable? public class Class1 { public string A { get; set; } public...
Nikaniki asked 22/11, 2010 at 18:50

3

Solved

In this article, Jon Skeet mentioned that he usually uses this kind of algorithm for overriding GetHashCode(). public override int GetHashCode() { unchecked // Overflow is fine, just wrap { int...
Sarilda asked 14/7, 2012 at 5:27

4

Solved

Let's say I have a class public class MyClass { public string Type { get; set; } public int Id { get; set; } } and I have a collection class that is simply a strongly typed List public ...
Deltoro asked 22/10, 2013 at 15:1

3

Solved

To my surprise the folowing method produces a different result in debug vs release: int result = "test".GetHashCode(); Is there any way to avoid this? I need a reliable way to hash a string and...
Tiemroth asked 23/9, 2011 at 19:59

4

Solved

When i am using dictionaries sometimes I have to change the default Equals meaning in order to compare Keys. I see that if I override the Equals and GetHashCode on the key's class or i create a new...
Dolmen asked 16/6, 2013 at 20:7

1

Solved

Given two identical anonymous type objects: {msg:"hello"} //anonType1 {msg:"hello"} //anonType2 And assume that they haven't resolved to the same type (e.g. they might be defined in different as...
Getty asked 13/5, 2013 at 8:6

© 2022 - 2024 — McMap. All rights reserved.