C# - 数字后缀

发布于 2024-09-16 04:09:48 字数 563 浏览 4 评论 0原文

可能的重复:
十进制类型的声明后缀

大家好,

在下面的代码片段中; 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技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

回首观望 2024-09-23 04:09:48

我相信您正在寻找的术语是“后缀”。

示例:

1;    // int
1.0;  // double
1.0f; // float
1.0m; // decimal
1u;   // uint
1L;   // long
1UL;  // ulong

I believe the term you're looking for is "suffix".

Examples:

1;    // int
1.0;  // double
1.0f; // float
1.0m; // decimal
1u;   // uint
1L;   // long
1UL;  // ulong
半﹌身腐败 2024-09-23 04:09:48

这确实是一个很小的清单。

F:  float
D:  double
U:  uint
L:  long
UL: ulong
M:  decimal

当然,普通整数值本身会被解释为 int,除非它太大而无法成为 int,在这种情况下它是 long,除非它对于long来说太大了,在这种情况下它是一个ulong。如果它对于 ulong 来说太大,则不能将其用作文字(据我所知)。

带有小数点的值会自动解释为(正如您自己发现的那样)为 double

It's a pretty small list, really.

F:  float
D:  double
U:  uint
L:  long
UL: ulong
M:  decimal

Of course a plain integral value by itself is interpreted as an int, unless it's too big to be an int in which case it's a long, unless it's too big for a long in which case it's a ulong. If it's too big for a ulong, 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.

红ご颜醉 2024-09-23 04:09:48

https://www.dotnetperls.com/suffix - 他们简单地称之为数字后缀< /代码>
(http://msdn.microsoft.com/en- us/library/b1e65aza(VS.71).aspx - 也是此处的后缀)

后缀类型:unsigned int

角色:U

示例:uint x = 100U;

后缀类型:长

角色:L

示例:长 x = 100L;

后缀类型:unsigned long

字符:UL

示例:ulong x = 100UL;

后缀类型:float

角色:F

示例:float x = 100F;

后缀类型:双

角色:D

示例:双倍 x = 100D;

后缀类型:十进制

角色:M

示例:十进制 x = 100M;

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)

Suffix type: unsigned int

Character: U

Example: uint x = 100U;

Suffix type: long

Character: L

Example: long x = 100L;

Suffix type: unsigned long

Character: UL

Example: ulong x = 100UL;

Suffix type: float

Character: F

Example: float x = 100F;

Suffix type: double

Character: D

Example: double x = 100D;

Suffix type: decimal

Character: M

Example: decimal x = 100M;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文