问题描述
这叫什么?
double d1 = 0d;
decimal d2 = 0L;
float d3 = 0f;
我在哪里可以找到我可以使用的字符的参考?如果我想将 0
转换为 short
,我需要哪个字母?
And where can I find a reference of characters I can use? If I want to cast 0
to short
, which letter I need?
推荐答案
最好的来源是 C# 规范,特别是 文字.
The best source is the C# specification, specifically section Literals.
相关位:
整数字面量的类型确定如下:
The type of an integer literal is determined as follows:
- 如果字面量没有后缀,则它具有可以表示其值的以下类型中的第一个:
int
、uint
、long
,ulong
. - 如果文字以 U 或 u 为后缀,则它具有可以表示其值的以下类型中的第一个:
uint
、ulong
. - 如果文字以 L 或 l 为后缀,则它具有以下类型中的第一个可以表示其值:
long
、ulong
. - 如果文字以 UL、Ul、uL、ul、LU、Lu、lU 或 lu 为后缀,则为
ulong
类型.
- If the literal has no suffix, it has the first of these types in which its value can be represented:
int
,uint
,long
,ulong
. - If the literal is suffixed by U or u, it has the first of these types in which its value can be represented:
uint
,ulong
. - If the literal is suffixed by L or l, it has the first of these types in which its value can be represented:
long
,ulong
. - If the literal is suffixed by UL, Ul, uL, ul, LU, Lu, lU, or lu, it is of type
ulong
.
如果没有指定real_type_suffix,那么真实字面量的类型是double
.否则,实数类型后缀决定实数字面量的类型,如下:
If no real_type_suffix is specified, the type of the real literal is double
. Otherwise, the real type suffix determines the type of the real literal, as follows:
以 F 或 f 为后缀的实数是
float
类型.[…]
以 D 或 d 为后缀的实数是 double
类型.[…]
A real literal suffixed by D or d is of type double
. […]
以 M 或 m 为后缀的实数是 decimal
类型.[…]
A real literal suffixed by M or m is of type decimal
. […]
这意味着字母(或字母)被称为后缀".short
是没有办法用这种方式表示的,所以只能用 (short)0
,或者只用 short x = 0;
.
That means the letter (or letters) is called "suffix". There is no way to represent short
this way, so you have to use (short)0
, or just short x = 0;
.
这篇关于数字后面的字母,叫什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!