C# - 数字后缀
可能的重复:
十进制类型的声明后缀
大家好,
在下面的代码片段中; RewardValue 是一个小数:
dto.RewardValue = 1.5;
现在,这给了我以下错误:
“无法将源类型双精度转换为目标类型十进制”
有道理,并且可以通过将该行代码更改为此轻松修复:
dto.RewardValue = 1.5m;
现在,“m”将其转换为一个小数,一切都很好。
有谁知道我可以在哪里找到所有这些“m”类型运算符的列表? (如果您能让我知道这些术语的正确术语,我将不胜感激)
编辑:感谢 HCL 和 MartyIX 让我知道这些被称为“后缀”
Possible Duplicate:
Declaration suffix for decimal type
Hey everyone,
In the following snippet of code; RewardValue is a decimal:
dto.RewardValue = 1.5;
Now, this gives me the following error:
"Cannot convert source type double to target type decimal"
Makes sense, and is easily fixable by changing that line of code to this:
dto.RewardValue = 1.5m;
Now, the "m" converts that to a decimal and all is good.
Does anybody know of somewhere where I could find a list of all those "m" type operators? (and if you could let me know what the proper term for those are, it would be greatly appreciated)
EDIT: Thanks to HCL and MartyIX for letting me know that these are referred to as "suffixes"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我相信您正在寻找的术语是“后缀”。
示例:
I believe the term you're looking for is "suffix".
Examples:
这确实是一个很小的清单。
当然,普通整数值本身会被解释为
int
,除非它太大而无法成为int
,在这种情况下它是long
,除非它对于long
来说太大了,在这种情况下它是一个ulong
。如果它对于ulong
来说太大,则不能将其用作文字(据我所知)。带有小数点的值会自动解释为(正如您自己发现的那样)为
double
。It's a pretty small list, really.
Of course a plain integral value by itself is interpreted as an
int
, unless it's too big to be anint
in which case it's along
, unless it's too big for along
in which case it's aulong
. If it's too big for aulong
, you can't use it as a literal (as far as I know).A value with a decimal point in it is automatically interpreted (as you found out for yourself) as a
double
.https://www.dotnetperls.com/suffix - 他们简单地称之为
数字后缀< /代码>
(http://msdn.microsoft.com/en- us/library/b1e65aza(VS.71).aspx - 也是此处的后缀)
https://www.dotnetperls.com/suffix - they call it simply
numeric suffixes
(http://msdn.microsoft.com/en-us/library/b1e65aza(VS.71).aspx - also suffix here)
我相信它被称为“数字垃圾”:
http://www.blackwasp.co.uk/CSharpNumericLiterals.aspx
I believe it's called a "numeric litteral":
http://www.blackwasp.co.uk/CSharpNumericLiterals.aspx