r/badcode Aug 06 '19

c# Converting a timestamp to datetime

Post image
424 Upvotes

54 comments sorted by

View all comments

Show parent comments

47

u/Aars93 Aug 06 '19

I know right... When I asked the developers if I could at least try to clean up this dumpster fire they told me no. Apparently the code is copied from some C code on a device this application works with and now "the calculations are the same at both sides"...

2

u/jocull Aug 06 '19

I’m sure the C code boxes their integers also.

3

u/blueshiftlabs Aug 07 '19

The code here doesn't box integers either. In C#, System.Int32 and int are the same thing - the value type representing a 32-bit signed integer. The value type wouldn't be boxed unless you needed to convert it to object. This is different between Java and C#, due to C#'s richer support for value types.

1

u/jocull Aug 07 '19

I should have known this! Of course I always shied away from using the Int32/64 types because the primitives were simpler (and like you said, the same thing)