I'm confused!
Today is November 3rd
DateTime DateTime = new DateTime(2010,11,3);
long shazbot = 1000000000 * DateTime.Day;
shazbot comes out to -1294967296
Huh???
shazbot may be a long, but neither 1000000000 or DateTime.Day are. So, C# does int multiplication first (which results in an overflow) then casts it to a long to store in shazbot.
If you want a long result, make one of them a long, like this:
long shazbot = 1000000000L * DateTime.Day;
Edit: C# gives you a warning if you use l instead of L. Fixed.
Cast to long like this:
long shazbot = 1000000000L * DateTime.Day;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With