如何指定无铸造短整型常量? [英] How to specify a short int constant without casting?
问题描述
有没有指定我的变量是一个短整型的方法吗?
我正在寻找类似到M后缀小数东西。对于小数,我也没有说。
VAR D =(十进制)1.23;
我可以只写如下:
变种D = 1.23M;
有没有写这个
<$办法p $ p>
变种S = SomeLiteralWithoutCast
让S是暗示是短整型?
简短的回答,的没有的。在C#中,有没有信取值
,可以用来作为 VAR一个= 123S
这将表明, A
的类型为短
。有→
为长
,˚F
为浮动
, D
为双击
, M
为小数
,而不是取值
。 。这将是很好,如果有,但没有
VAR一个= 1M; //十进制
VAR一个= 1L; //长
VAR一个= 1F; //浮动
VAR一个= 1D; //双
变种A = 1; // INT
VAR一个= 1U; // UINT
VAR一个= 1UL; // ULONG
而不是
VAR一个= 1S; //不可能的,你必须使用(短)1;
Is there a way to specify that my variable is a short int? I am looking for something similar to M suffix for decimals. For decimals, I do not have to say
var d = (decimal)1.23;
I can just write as follows:
var d = 1.23M;
Is there a way to write this
var s = SomeLiteralWithoutCast
so that s is implied to be short int?
Short answer, No. In C#, there's no letter S
that could be used as var a = 123S
that would indicate that a
is of type short
. There's L
for long
, F
for float
, D
for double
, M
for decimal
, but not S
. It would be nice if there was, but there isn't.
var a = 1M; // decimal
var a = 1L; // long
var a = 1F; // float
var a = 1D; // double
var a = 1; // int
var a = 1U; // uint
var a = 1UL; // ulong
but not
var a = 1S; // not possible, you must use (short)1;
这篇关于如何指定无铸造短整型常量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!