Yossi Dahan [BizTalk]

Google
 

Monday, May 10, 2010

What’s bigger than byte.MaxValue?

Well – byte.MinValue, of course!

Only that I didn’t think of that, and neither did the person whose code raised the weird exception that led me to this.

Can’t find anything on this on the web, which usually suggest everybody knows this but me, but it turns out that -

byte b = byte.MaxValue;
b++;
MessageBox.Show(b.ToString());



displays ‘0’, and so equally -



b = byte.MinValue ;
b--;
MessageBox.Show(b.ToString());


displays ‘255’



And I totally did not know that.



Conclusion – no matter how ‘efficient’ you want to be – don’t use bytes in a loop unless you know what you’re doing! :-)

1 Comments:

  • as the same as:

    UInt64 myUint64 = UInt64.MinValue;
    myUint64--;

    myUint64 is now 18446744073709551615

    :)

    looks like a feature for me :)

    By Blogger roni, at 12/05/2010, 11:18  

Post a Comment

<< Home