Search code examples
c#.netcastingx86anycpu

x86 / anycpu - difference in casting?


My code :

decimal fAnzahlAktuell = 12;
decimal fMenge = 2;
decimal fAnzahlReserviertPickpos = 0;

decimal a = ((decimal)(fAnzahlAktuell - fAnzahlReserviertPickpos)) > fMenge ? fMenge : (decimal)(fAnzahlAktuell - fAnzahlReserviertPickpos);
decimal b = (decimal)((fAnzahlAktuell - fAnzahlReserviertPickpos) > fMenge ? fMenge : (decimal)(fAnzahlAktuell - fAnzahlReserviertPickpos));

When i compile using x86 -> a and b both = 2

When i compile using anycpu -> a = 2 and b = 0

Can anybody explain why?!

EDIT : I am using VS2010 , .NET 4.0 on Windows 7 x64

enter image description here


Solution

  • Resolved it myself. It is a bug in VS2010 with x64 debugger ...

    https://connect.microsoft.com/VisualStudio/feedback/details/655793/edit-this-entry-misreporting-of-variable-values-when-debugging-x64-code-with-the-visual-studio-2010-debugger