devforall
devforall

Reputation: 7337

Dictionary GetHashCode Inconsistant

i am using this hash for data retrival, but the data retrival is very uniform sometimes i get data under 200 millisecs and sometimes its over a sec.. can any give me some suggestions

public override int GetHashCode()

{

return   
this.DomainID.GetHashCode() *(851) *    
(this.A.HasValue ? this.A.GetHashCode() : 1) * (851) *    
((this.C != null ? this.C.ToLower().GetHashCode() : 1)^     
(this.Ap != null ? this.Ap.ToLower().GetHashCode() : 1) * (851) *    
(this.Ks != null ? this.Ks.ToLower().GetHashCode() : 1)) *  
(this.Le != null ? Le.ToLower().GetHashCode() : 1);

}

Upvotes: 1

Views: 185

Answers (2)

CodingInsomnia
CodingInsomnia

Reputation: 1863

The code itself looks alright at a first glance, but there is a lot of things that we don't see. What types are DomainID, A, C, Ap, Ks and Le for example? And how are their GetHashCode-methods implemented?

Upvotes: 1

Zyon
Zyon

Reputation: 361

It might suggest that one of your conditions is slower than the rest. Maybe the ToLower() is an expensive call dependant on which values in the the this are null

Upvotes: 0

Related Questions