gethashcode Questions

5

Solved

It is my understanding that GetHashCode will return the same value for two different instances which share the same values. The MSDN documentation is a bit fuzzy on this point. A hash code is a ...
Guarneri asked 4/4, 2013 at 17:14

2

Solved

I'm just curious because I guess it will have impact on performance. Does it consider the full string? If yes, it will be slow on long string. If it only consider part of the string, it will have b...
Gerhard asked 2/3, 2013 at 12:29

5

Many of my questions here on SO concerns IEquatable implementation. I found it being extremely difficult to implement correctly, because there are many hidden bugs in the naïve implementation, and ...
Bougie asked 20/8, 2009 at 16:48

2

I have a class with string properties and I need to override GetHashCode() method. class A { public string Prop1 { get; set; } public string Prop2 { get; set; } public string Prop3 { get;...
Dodiedodo asked 28/11, 2012 at 5:39

3

Solved

I have never really done this before so i was hoping that someone could show me the correct what of implementing a override of Except() and GetHashCode() for my class. I'm trying to modify ...
Poker asked 16/2, 2012 at 19:15

1

Solved

Why is it that 17m.GetHashCode() == 17d.GetHashCode() (m=decimal, d=double) Additionally, as expected 17f.GetHashCode() != 17d.GetHashCode() (f=float) This appears to be true for both net3.5 and ...
Fustian asked 2/9, 2012 at 13:53

2

Solved

I am using Entity Framework in my application. I implemented with the partial class of an entity the IEquatable<T> interface: Partial Class Address : Implements IEquatable(Of Address) 'Othe...
Administer asked 13/4, 2010 at 3:45

4

Solved

Consider the following objects: class Route { public int Origin { get; set; } public int Destination { get; set; } } Route implements equality operators. class Routing { public List<Route...
Stimulus asked 12/5, 2012 at 21:13

2

Solved

I have some classes as below, i have implemented the Equals(Object) method for almost all of them. But i don't know how to write GetHashCode() . As far I used these data types as value type in a Di...
Bannasch asked 22/3, 2012 at 17:59

4

Solved

The VS2005 documentation Guidelines for Overloading Equals() and Operator == (C# Programming Guide) states in part Overriding operator == in non-immutable types is not recommended. The newer ....
Mackay asked 14/3, 2012 at 19:46

2

Solved

I tried with batch of random strings, all values I got are positive, but I wondering: Will String.GetHashCode() return negative or 0? Since the return value is int, so I guess it might be, so if ...
Kapor asked 31/1, 2012 at 18:14

2

Solved

Google Guava provides nice helpers to implement equals and hashCode like the following example demonstrates: public int hashCode() { return Objects.hashCode(lastName, firstName, gender); } Is t...
Rickettsia asked 27/1, 2012 at 16:8

2

Solved

Seeing from Artech's blog and then we had a discussion in the comments. Since that blog is written in Chinese only, I'm taking a brief explanation here. Code to reproduce: [AttributeUsage(Attribut...
Salinas asked 12/1, 2012 at 17:26

4

Solved

I have an entity class like this (with lots of stuff missing): class Parent { private readonly Iesi.Collections.Generic.ISet<Child> children = new Iesi.Collections.Generic.HashedSet<Chi...
Cloaca asked 15/11, 2011 at 20:2

7

Solved

I am porting something from Java to C#. In Java the hashcode of a ArrayList depends on the items in it. In C# I always get the same hashcode from a List... Why is this? For some of my objects th...
Harpp asked 25/5, 2010 at 18:27

4

Solved

Hi I have a class with 6 string properties. A unique object will have different values for atleast one of these fields To implement IEqualityComparer's GetHashCode function, I am concatenating all...
Colander asked 5/9, 2011 at 14:8

3

Solved

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 in...
Suilmann asked 5/9, 2011 at 20:10

1

Solved

I have a class: public abstract class AbstractDictionaryObject { public virtual int LangId { get; set; } public override bool Equals(object obj) { if (obj == null || obj.GetType() != GetType...
Pryer asked 10/8, 2011 at 5:28

2

Solved

I've implemented a class that overloads the == and != operators. This seems to work fine; however, I get the warning 'type' defines operator == or operator != but does not override Object.Equals(o...
Tungting asked 25/7, 2011 at 21:56

4

Solved

I declared a C# line of code like so int hashcode = "apple".GetHashCode(); On my computer, a computer at work, and a friend's computer, the result was 1657858284. On a development server, the re...
Fusible asked 24/5, 2011 at 17:59

1

Solved

I need to use Dictionary<long, string> collections that given two instances d1 and d2 where they each have the same KeyValuePair<long, string> contents, which could be inserted in any o...
Secunda asked 29/5, 2011 at 14:28

3

Solved

Should we override both Equals and GetHashCode properties when implementing a custom class instances comparison? In the following code I have a collection of classes. The class A is compared by th...
Inshrine asked 12/5, 2011 at 16:30

3

Solved

The program was working with this implementation: class Instrument { public string ClassCode { get; set; } public string Ticker { get; set; } public override string ToString() { return " Clas...
Negligible asked 18/4, 2011 at 8:6

3

Solved

What would be the best way to override the GetHashCode function for the case, when my objects are considered equal if there is at least ONE field match in them. In the case of generic Equals metho...
Thitherto asked 5/4, 2011 at 15:53

3

Solved

Which of the following is correct/better, considering that identity property could be null. public override int GetHashCode() { if (ID == null) { return base.GetHashCode(); } return ID.GetHash...
Undervalue asked 22/2, 2011 at 12:34

© 2022 - 2024 — McMap. All rights reserved.