c# - why is it not possible to compare IntPtr.Zero and default(IntPtr)? -


i learned hard way intptr.zero cannot compared default(intptr). can tell me why?

intptr.zero == new intptr(0) -> "could not evaluate expression" intptr.zero == default(intptr) --> "could not evaluate expression" intptr.zero == (intptr)0 -> "could not evaluate expression"  intptr.zero.equals(intptr.zero) --> "enum value out of legal range" exception intptr.zero.equals(default(intptr)) --> "enum value out of legal range" exception  intptr.zero == intptr.zero --> true new intptr(0) == new intptr(0) --> true 

works me in compiled code in vs 2010, vs 2008, vs 2005 sp1, mono 1.2.6. managed reproduce both problems in watch window of visual studio 2005 (i tried vs 2005 sp1), compiled code works expected. (by both problems mean problem 1: "could not evaluate expression", problem 2: "enum value out of legal range".) thus, pointed out of comment authors, vs 2005 watch window bug stumbled upon. surprisingly hard find link relevant bug report...

otherwise in such cases i'd start reflection see types try compare (replace console.out meaningful stream have access to):

console.writeline("new intptr(0) type is: " + new intptr(0).gettype()); console.writeline("intptr.zero type is: " + intptr.zero.gettype()); 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -