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
2 answers

Issue with containskey and gethashcode

I am currently trying to use the containskey method to check if a dictionary i have contains a certain key of a custom type. To do this i should override the gethashcode function, which i have, however the containskey method is still not working.…
Ken de Jong
  • 219
  • 1
  • 11
0
votes
2 answers

Compare Objects' properties using hashcode

I need to know the ways to compare many objects using hashcode. So here is one of the class. public class Test: IEquatable { public Test() { } public string ID { get; set; } public string Name{ get; set; } public…
king jia
  • 692
  • 8
  • 20
  • 43
0
votes
1 answer

Can I Implement GetHashCode for my custom Collection

I have a custom collection as shown below public class CustomCollection:IEnumerable, IEnumerator { int size = 0; int current = 0; int position = -1; CustomComparer cmp = new CustomComparer(); T[] collection =…
Vikram
  • 1,617
  • 5
  • 17
  • 37
0
votes
2 answers

GetHashCode conflicts

I know it's not very smart to use HashCode as a unique identifier, but let's say I have two variables on the same HashCode is the only way I can get them, how can I tell the difference?
Hodaya Shalom
  • 4,327
  • 12
  • 57
  • 111
0
votes
1 answer

Is it possible a hash code of mobile number is converted in to real number i want to know mobile number from my mobile number hash code

Is it possible a hash code of mobile number is converted in to real number i want to know mobile number from given mobile number hash code?Just as a testing purpose
0
votes
3 answers

Can I implement a base GetHashCode() that will work for all extensions of my abstract base class?

I got reading this question here which led me to this article here. I've got an abstract base class that allows me to constrain methods to accept only my classes that extend my abstract base class (basic polymorphism). My question is: Can I…
JMD
  • 7,331
  • 3
  • 29
  • 39
0
votes
2 answers

Why is used Connection.GetHashCode in C#?

When I examined a project(my company codes). I looked this: public override int GetHashCode() { unchecked { int result = 17; result = result * 23 + ((connection != null) ? this.connection.GetHashCode() : 0); return…
AliRıza Adıyahşi
  • 15,658
  • 24
  • 115
  • 197
0
votes
3 answers

Instances of my class don't want to act properly as dictionary keys interchangeably with strings

I created a sort of string wrapper class and want to use its instances as dictionary keys interchangeably with usual strings. I overrode GetHashCode and Equals and got results that seem strange. I've isolated the issue. Please look at my code and…
thorn0
  • 9,362
  • 3
  • 68
  • 96
0
votes
3 answers

.NET equivalent to java.util.Arrays.hashCode() function for arrays of intrinsic types?

Is there a.NET utility class equivalent to java.util.Arrays.hashCode() for arrays of intrinsic types such as int[], short[], float[], etc.? Obviously I could write my own utility class but was trying to find one already available in the .NET…
David G
  • 6,249
  • 4
  • 33
  • 31
0
votes
3 answers

How to override equals for specific NHibernate class

I am struggling to figure out how I should override equals and get hashcode for a class I am writing using NHibernate. Basic business scenario is that users cannot re-use the same password within a 90 day limit. So I have a "user" that has many…
Todd
  • 1,461
  • 2
  • 13
  • 27
0
votes
2 answers

When to use a GUID for a class

I'm working on a simple application with a few classes. This all started when I wanted to use the Remove method on a List. This method requires that you override the Equals and the GetHashCode methods for the Car type. In this situation, I…
Andrew B Schultz
  • 1,512
  • 1
  • 23
  • 41
-1
votes
1 answer

GetHashCode implementation using tuples for derived class

I like to implement GetHashCode using tuples, as described here https://intellitect.com/overidingobjectusingtuple/. However, this doesn't seem to work for a derived class. For example: class Base { public int Prop1 { get; set; } public int…
UnionP
  • 1,251
  • 13
  • 26
-1
votes
1 answer

HashSet on collections of objects

I have an object of type T which implements IEquatable (methods Equals and GetHashCode are implemented). I use these objects in a HashSet. But for my development I need to upgrade the elements of this hash set to collections of T objects…
xuanphong
  • 43
  • 7
-1
votes
1 answer

I'd like to know how can I write good GetHashCode() for ordered list

I made a class that include List.(T is a struct I made.) And I want to override Equals() and GetHashCode(). So I need to make HashCode from List. How can I make good HashCode from ordered list?
kdm1jkm
  • 5
  • 1
-1
votes
3 answers

Cannot implicitly convert type 'string' to 'byte[]' using C#

For my project I need to get the Image sourse as hash code like this 28F996F0.jpg. I am trying the following code to get this value but having one error-Cannot implicitly convert type 'string' to 'byte[]'. var Image=…
harry.luson
  • 247
  • 7
  • 19
1 2 3
22
23