Tutorial :c# sizeof decimal?



Question:

Unclear on the sizeof for decimal types. Does the size in bytes vary by precision as in sql server? Is the precision variable for the c# type 'decimal'?

I don't want to turn on unsafe code to just call sizeof on a decimal type. How would you approach this?


Solution:1

As others have said, decimal is always 16 bytes (128 bits). The precision of decimal is always 28/29 digits. It's a floating point type, unlike SQL's DECIMAL type. See my article on it for more details.


Solution:2

The decimal keyword indicates a 128-bit data type.

Source: MSDN


Solution:3

The size of a System.Decimal in the .NET Framework is fixed at 16 Bytes.


Solution:4

128-bit precise decimal values with 28-29 significant digits, 128 bit = 16 byte


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »