gpt4 book ai didi

c# - .Net 数值类型初始化标识符列表

转载 作者:太空狗 更新时间:2023-10-29 22:18:15 25 4
gpt4 key购买 nike

我正在寻找 C# 和 VB.Net 的数字类型初始化标识符列表。

例如:

Dim x = 1D 'Decimal'
Dim y = 1.0 'initializes to float'

这是列表:

标识符不区分大小写

VB.Net

Int32   = 1, IDouble  = 1.0, R, 1.0e5Decimal = DSingle  = F, !Int16   = SUInt64  = L, UL

C#

最佳答案

C#

Section 1.8 of the C# specification 包含这些值。

integer-type-suffix: one of U u L l UL Ul uL ul LU Lu lU lu

real-type-suffix: one of F f D d M m

Section 2.4.4.2 详细说明了 Integer 类型:

The type of an integer literal is determined as follows:

  • 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.

Section 2.4.4.3 针对 Real 类型详细说明了这一点:

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:

  • A real literal suffixed by F or f is of type float. For example, the literals 1f, 1.5f, 1e10f, and 123.456F are all of type float.
  • A real literal suffixed by D or d is of type double. For example, the literals 1d, 1.5d, 1e10d, and 123.456D are all of type double.
  • A real literal suffixed by M or m is of type decimal. For example, the literals 1m, 1.5m, 1e10m, and 123.456M are all of type decimal. This literal is converted to a decimal value by taking the exact value, and, if necessary, rounding to the nearest representable value using banker's rounding (Section 4.1.7). Any scale apparent in the literal is preserved unless the value is rounded or the value is zero (in which latter case the sign and scale will be 0). Hence, the literal 2.900m will be parsed to form the decimal with sign 0, coefficient 2900, and scale 3.

VB

同样,VB 规范包含 IntegerFloating point 文字的详细信息。

对于整数:

ShortCharacter ::= S
IntegerCharacter ::= I
LongCharacter ::= L

对于 float :

SingleCharacter ::= F
DoubleCharacter ::= R
DecimalCharacter ::= D

关于c# - .Net 数值类型初始化标识符列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/685962/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com