在C / c# / etc。你可以告诉编译器字面数不是它看起来是什么(例如。, float代替double, unsigned long代替int):

var d = 1.0;  // double
var f = 1.0f; // float
var u = 1UL;  // unsigned long

etc.

谁能给我一份清单吗?我正在专门寻找短或Int16的后缀。


当前回答

从整数字面量:

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.

和来自Real literals:

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.

其他回答

如果你的变量不是short类型,你必须显式强制转换:

Object s = (Int16) 1;

没有简称。用短的s = 1;。

var myValue = unchecked((short)0x7F00);

字面值是int,因此必须转换为目标类型。 如果发生值溢出,则需要检查。

从整数字面量:

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.

和来自Real literals:

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.

var d  = 1.0d;  // double
var d0 = 1.0;   // double
var d1 = 1e+3;  // double
var d2 = 1e-3;  // double
var f  = 1.0f;  // float
var m  = 1.0m;  // decimal
var i  = 1;     // int
var ui = 1U;    // uint
var ul = 1UL;   // ulong
var l  = 1L;    // long

我想就这些了……short/ushort/byte/sbyte没有文字说明符