可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
回答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.
回答2:
The decimal keyword indicates a 128-bit data type.
Source: MSDN
回答3:
The size of a System.Decimal in the .NET Framework is fixed at 16 Bytes.
回答4:
128-bit precise decimal values with 28-29 significant digits, 128 bit = 16 byte