Click here to Skip to main content
15,897,518 members
Home / Discussions / C#
   

C#

 
AnswerRe: how can i create textBox in C# with email autocomplate exactly like "outlook To field" Pin
Shameel14-Feb-12 2:26
professionalShameel14-Feb-12 2:26 
QuestionListbox in user control is hiding in the tablelayoutpanel control Pin
Ravi Rangari14-Feb-12 1:29
Ravi Rangari14-Feb-12 1:29 
AnswerRe: Listbox in user control is hiding in the tablelayoutpanel control Pin
GParkings14-Feb-12 2:05
GParkings14-Feb-12 2:05 
GeneralRe: Listbox in user control is hiding in the tablelayoutpanel control Pin
Ravi Rangari14-Feb-12 16:33
Ravi Rangari14-Feb-12 16:33 
GeneralRe: Listbox in user control is hiding in the tablelayoutpanel control Pin
GParkings14-Feb-12 23:52
GParkings14-Feb-12 23:52 
GeneralRe: Listbox in user control is hiding in the tablelayoutpanel control Pin
Ravi Rangari16-Feb-12 0:11
Ravi Rangari16-Feb-12 0:11 
QuestionGetHashCode override for a value wrapper. Is mutable ok? Pin
GParkings13-Feb-12 23:32
GParkings13-Feb-12 23:32 
AnswerRe: GetHashCode override for a value wrapper. Is mutable ok? Pin
BobJanova14-Feb-12 0:42
BobJanova14-Feb-12 0:42 
This could, I think, potentially cause problems if you're using instances of this class in the key of dictionaries. But no more so than if you put _value in there instead, and there's not really a way to avoid it with mutable types.

I think that you are only going to be sacrificing a bit of performance, not creating subtle bugs, because the .Net hashtable will look through all the items if it doesn't get a hash hit. Generally, you wouldn't put mutable things into collections as a key anyway.

There are only two 'golden rules' of GetHashCode, to quote the documentation[^]:
If two objects compare as equal, the GetHashCode method for each object must return the same value. However, if two objects do not compare as equal, the GetHashCode methods for the two object do not have to return different values.

The GetHashCode method for an object must consistently return the same hash code as long as there is no modification to the object state that determines the return value of the object's Equals method. Note that this is true only for the current execution of an application, and that a different hash code can be returned if the application is run again.


You generally want to use as much of the state (which you compare within an Equals override) as possible to make the hash code uniqueness work well, and that means that if you mutate the object you change its hash code, which could cause a minor slowdown next time you look 'it' (i.e. something that matches it by Equals) up.

So in conclusion, you're okay, but good question, and it's good practice not to mutate things (at least, not to mutate the parts of them which are part of their equality semantics) if they're being used as dictionary keys.
GeneralRe: GetHashCode override for a value wrapper. Is mutable ok? Pin
GParkings14-Feb-12 0:48
GParkings14-Feb-12 0:48 
GeneralRe: GetHashCode override for a value wrapper. Is mutable ok? Pin
Daniel Grunwald15-Feb-12 0:37
Daniel Grunwald15-Feb-12 0:37 
AnswerRe: GetHashCode override for a value wrapper. Is mutable ok? Pin
PIEBALDconsult14-Feb-12 2:47
mvePIEBALDconsult14-Feb-12 2:47 
GeneralRe: GetHashCode override for a value wrapper. Is mutable ok? Pin
GParkings14-Feb-12 2:56
GParkings14-Feb-12 2:56 
QuestionRaysharp Client SDK Pin
jayesh86.pkd13-Feb-12 22:49
jayesh86.pkd13-Feb-12 22:49 
AnswerRe: Raysharp Client SDK Pin
Dave Kreskowiak14-Feb-12 2:08
mveDave Kreskowiak14-Feb-12 2:08 
GeneralRe: Raysharp Client SDK Pin
jayesh86.pkd14-Feb-12 21:55
jayesh86.pkd14-Feb-12 21:55 
QuestionVisual C# dictionary Pin
csshtml13-Feb-12 22:07
csshtml13-Feb-12 22:07 
AnswerRe: Visual C# dictionary Pin
V.14-Feb-12 0:44
professionalV.14-Feb-12 0:44 
AnswerRe: Visual C# dictionary Pin
Eddy Vluggen14-Feb-12 5:06
professionalEddy Vluggen14-Feb-12 5:06 
AnswerRe: Visual C# dictionary Pin
PIEBALDconsult14-Feb-12 5:12
mvePIEBALDconsult14-Feb-12 5:12 
GeneralRe: Visual C# dictionary Pin
csshtml14-Feb-12 6:34
csshtml14-Feb-12 6:34 
QuestionFolder lock Pin
aniperiye13-Feb-12 19:59
aniperiye13-Feb-12 19:59 
AnswerRe: Folder lock Pin
lukeer13-Feb-12 20:49
lukeer13-Feb-12 20:49 
QuestionC sharp windows service Pin
candogu13-Feb-12 19:53
candogu13-Feb-12 19:53 
AnswerRe: C sharp windows service Pin
V.13-Feb-12 20:55
professionalV.13-Feb-12 20:55 
GeneralRe: C sharp windows service Pin
candogu14-Feb-12 0:17
candogu14-Feb-12 0:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.