如何在不强制转换的情况下指定短整型文字? [英] How to specify a short int literal without casting?
本文介绍了如何在不强制转换的情况下指定短整型文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法指定我的变量是一个短整数?我正在寻找类似于小数的 M 后缀的东西.对于小数,我不必说
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;
我可以这样写:
var d = 1.23M;
有没有办法写这个
var s = SomeLiteralWithoutCast
所以 s 被暗示为短整数?
so that s is implied to be short int?
推荐答案
简短的回答,否.在 C# 中,没有字母 S
可以用作 var a = 123S
表示 a
的类型为 short代码>.
L
表示long
,F
表示float
,D
表示double
,M
表示decimal
,但不是S
.如果有就好了,但没有.
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
但不是
var a = 1S; // not possible, you must use (short)1;
这篇关于如何在不强制转换的情况下指定短整型文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文