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

Ask About This Hash / Encryption Combination is work

today i have a lil problem for recognize this combination hash is work, im looking when im log into my account in some apps, but i get this hash, and change everytime when i login, even with same password / pin, can someone help me about what is…
0
votes
3 answers

What are the rules I should follow to ensure GetHashCode() method returns unique value for an object?

What are the rules I should follow to ensure GetHashCode() method returns unique value for an object? For example: Should I include some prive members for the calculation? Should I multiply instead of sum? Can I be sure that I am generating a…
pencilCake
  • 51,323
  • 85
  • 226
  • 363
0
votes
1 answer

C# – How to override GetHashCode for List to calculate ETag with T being a record

For a NetCore Web API GET method I need to caluclate the ETag for a returned List. T is the DTO in the form of a record that holds only primitive types. I wanted to calculate a hash of the list. I was searching for information about how…
M. Koch
  • 525
  • 4
  • 20
0
votes
0 answers

How can i fix linkedlist using with iterator in Java?

When create a linkedlist in hash class search method, my iterator does not work with it. What can i use instead of iterator? How can i fix it. public static void search(String keyword){ String hashString = hash(new…
Anon
  • 41
  • 1
  • 6
0
votes
0 answers

Is it safe to implement GetHashCode by returning an unique ID from the object?

Let's say I have a POCO that represents a database row. I have access to the ID of that row. Is it safe to implement GetHashCode and Equals by leveraging that unique ID ? public class Project { public string ID { get; } public string Name {…
Arthur Attout
  • 2,701
  • 2
  • 26
  • 49
0
votes
2 answers

GetHashCode for Dictionary items

I override the Equals method for one of my class. In the method, I check the equality of each pair of a dictionary with those of the dictionary of another instance, like the following does public override bool Equals (object obj) { …
tom
  • 14,273
  • 19
  • 65
  • 124
0
votes
0 answers

Visual Studio offers two versions of code generation for Equals and GetHashCode

Visual Studio is offering to generate code for Equals() and GetHashCode() two ways. public class Identifier { public string firstName; public string lastName; internal Identifier(string firstName, string lastName) { this.firstName =…
H2ONaCl
  • 10,644
  • 14
  • 70
  • 114
0
votes
1 answer

Linq Union - IEqualityComparer and # of executions

Out of interest how does the GetHashCode of a concrete implementation of IEqualityComparer work? The reason that I ask is that I'm using linq to union two collections, and when only the left collection has an item GetHashCode is called twice.…
Tim Butterfield
  • 565
  • 5
  • 24
0
votes
1 answer

Linq Group by Complex Object (E.G list element of object)

I have an object like below; var json = @"{ 'TableNumber': '3', 'TableId': '81872d39-9480-4d2d-abfc-b8e4f33a43b6', 'tableMenuItems': [ { 'Id': '4664a2d3-c0af-443d-8af5-2bd21e71838b', 'Name': 'Bonfile', …
Cemal
  • 153
  • 2
  • 8
0
votes
2 answers

nhibernate gethashcode behaviour

I'm have been struggling the last 3 days with a funny, at least for me, behaviour. The basic concept is the following: An object is created in memory, this object has a list of children. This object is saved into the DB, the children are also saved,…
Ruben Monteiro
  • 315
  • 3
  • 15
0
votes
2 answers

How do you write a GetHashCode method for an object made of a string and a collection of int32?

There is a class of Products: public class ProductWithFeatures { public string Name { get; set; } public ICollection Features { get; set; } } public class Feature { public int Id { get; set; } public Feature(int Id) …
user13693463
0
votes
1 answer

Computed hashcode to lie within a particular range of values?

I have a function which looks like this: public int getHashcode(int shardCount){ String personid = ""; String servicedate = "2019-12-22T01:31:30.000Z"; HashCodeBuilder hashCodeBuilder = new HashCodeBuilder(); …
varsha Das
  • 41
  • 1
  • 2
  • 10
0
votes
7 answers

Referencing an object using its hashcode?

I have created an object, say details. I then assign: int x = details.GetHashCode(); Later in the program, I would like to access this object using the integer x. Is there a way to do this in C#? Many thanks Paul
Paul
  • 1
0
votes
2 answers

Implement a custom hashcode on a third party class

I'm using a Line class in VisualStudio C# project from a third party (no access to the source) My code is generating hundreds/thousands of line objects containing duplicates and I need to store them in some kind of collection (List, HashSet) for…
tlatev
  • 25
  • 4
0
votes
1 answer

What is equivalent for Java Objects.hash and Objects.hashCode in C#

Moving from Java to C# developer. In Java, I used a lot of Objects.hash(array) and Objects.hashCode(object) to build hash code of an object in hashCode function. I can't find any equivalent for those functions in C#. Any ideas? Indeed I can call…
LHA
  • 9,398
  • 8
  • 46
  • 85