Questions tagged [gethashcode]

GetHashCode is method of base Object class of .Net Framework.

GetHashCode is method of base Object class of .Net Framework. A hash code is a numeric value that is used to identify an object during equality testing. It can also serve as an index for an object in a collection. The GetHashCode method is suitable for use in hashing algorithms and data structures such as a hash table.

Important notes

  • Equality of GetHashCode value doesn't necessarily imply equality of objects. The equality must be verified using Equals.
  • Inequality of GetHashCode necessarily means inequality of objects.
344 questions
0
votes
0 answers

Blockchain in C# - hash value doesn't change despite of changing transaction details

I wanted to get started with blockchain development and I know how it works but for some strange reasons to me, when I make a change in previous transactions hash value doesn't change in the previous block either in next block. I have tried adding a…
0
votes
0 answers

HashSet EqualityComparer that returns equal if SetEquals: which GetHashCode?

Seems like How does HashSet Compare elements for equality, but different, because that question focusses on the IEqualityComparer used by the HashSet. I want to write an Equality Comparer that declares two hashsets to be equal if SetEquals returns…
Harald Coppoolse
  • 28,834
  • 7
  • 67
  • 116
0
votes
1 answer

IEquatable within a tolerance, how to implement GetHashCode()

I have a Point3d struct which implements IEquatable in the following manner: public override bool Equals(object obj) { return obj is Point3d p && Equals(p); } public bool Equals(Point3d other) { return Equals(other,…
Rob Kite
  • 395
  • 1
  • 11
0
votes
3 answers

Generate unique key from hashcode

I am having class below class Group { public Collection UserIds { get; set; } public int CreateByUserId { get; set; } public int HashKey { get; set; } } I want to generate some unique hashkey based on UsersIds[] and CreateByUserId…
Ankit Vaidya
  • 35
  • 1
  • 8
0
votes
2 answers

How to override GetHashCode on a Hashtable?

I would like override the GetHashCode method on a hashtable in C#. I use the hashtable as a multidimensional key in a complex object. How could do that ? Different order of Keys in hKey must return the same hashCode. Something like this doesn't…
Amenis
  • 1
  • 1
0
votes
1 answer

Overwriting GetHashCode (Enum plus Integer comparison)

I want to overwrite a GetHashCode method with following code: public override int GetHashCode() { var magicNumber1 = 5; var magicNumber2 = 3; return intType * magicNumber1 + (int)enumType * magicNumber2; } Is this a proper…
helpME1986
  • 933
  • 3
  • 12
  • 26
0
votes
1 answer

How to successfully hash System.Windows.Input.Key values with modifier key states?

I am trying to write a hashing algorithm that's gonna successfully hash System.Windows.Input.Key values with modifier key states, for instance: ctrl = false shift = true alt = false capslock = true numlock = false scroll lock = false key: A So a…
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
0
votes
1 answer

KeyEventArgs.Modifier to int32

I'm making a program to have user customizable hotkeys and I have pretty much everything working except for 1 hitch converting the modifier keys to int32 using gethashcode() private void hotBox1_KeyDown(object sender, KeyEventArgs e) { string…
Snowlove
  • 11
  • 3
0
votes
1 answer

e.keyChar does not work for Ctrl

This code shows hashcodes of pressed button, but when i press on Control button i does not do anything. Can help me someone? private void treeView1_KeyPress(object sender, KeyPressEventArgs e) { …
Irakli Lekishvili
  • 33,492
  • 33
  • 111
  • 169
0
votes
1 answer

Can GetHashCode() for the same double result in a different integer?

Is it possible for the GetHashCode() method to return different integer values for the same double value on different computers, operating systems, or architectures? For example, if I have the following code: public unsafe override int…
Vahid
  • 5,144
  • 13
  • 70
  • 146
0
votes
0 answers

How to implement GetHashcode for a difference-tolerant DateTime comparer?

I've implemented an IEqualityComparer which can compare two dates based on a tolerance value in milliseconds. If the difference between the two is less than the tolerance, they should be treated as equal. The Equals side is almost trivial…
Zoltán Tamási
  • 12,249
  • 8
  • 65
  • 93
0
votes
0 answers

contains function not calling the equals method to compare objects

I am using SQL query to get the Person object. This Person object has a set of interests which also I am getting from SQL query. Now when I try to check if a interest object is contained in this Person Object, then it is not calling the equals…
Tarun
  • 271
  • 1
  • 6
  • 18
0
votes
2 answers

Generating Hash Code for Object

I have a custom object (DataPointCollection) with two Integer properties and a Guid property. I want that object to generate a HashCode so that no two objects with the same values in those properties are added to a HashSet. I know I need to override…
Brandon Montgomery
  • 6,924
  • 3
  • 48
  • 71
0
votes
2 answers

GetHashCode breaks code

In my code I have the following class: public class ResourcePack { private int m_pirates; private int m_islands; private int m_enemy_drones; private int m_enemy_pirates; public ResourcePack() { this.m_pirates = 0; …
0
votes
1 answer

C# User class. GetHashCode implementation

I have simple class only with public string properties. public class SimpleClass { public string Field1 {get; set;} public string Field2 {get; set;} public string Field3 {get; set;} public List Children {get; set;} …
murzagurskiy
  • 1,273
  • 1
  • 20
  • 44