c#sizeof十进制?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/745270/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 23:33:01  来源:igfitidea点击:

c# sizeof decimal?

c#

提问by P a u l

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'?

十进制类型的 sizeof 不清楚。以字节为单位的大小是否与 sql server 中的精度不同?c# 类型的精度变量是“十进制”吗?

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

我不想打开不安全的代码来只在十进制类型上调用 sizeof 。你会如何处理这个问题?

采纳答案by Jon Skeet

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

正如其他人所说,decimal总是 16 字节(128 位)。的精度decimal始终为 28/29 位。它是一种浮点类型,与 SQL 的DECIMAL类型不同。有关更多详细信息,请参阅我的文章

回答by Tormod Fjeldsk?r

The decimal keyword indicates a 128-bit data type.

十进制关键字表示 128 位数据类型。

Source: MSDN

来源:MSDN

回答by Jose Basilio

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

.NET Framework 中 System.Decimal 的大小固定为 16 字节。

回答by Sachith

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

具有 28-29 位有效数字的 128 位精确十进制值,128 位 = 16 字节