如何在不强制转换的情况下指定简短的int文字? [英] How to specify a short int literal without casting?

查看:89
本文介绍了如何在不强制转换的情况下指定简短的int文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以指定我的变量为short int?
我正在寻找类似于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被暗示为short int?

so that s is implied to be short int?

推荐答案

简短答案,。在C#中,没有字母 S 可以用作 var a = 123S 来表示 a 的类型为 short L long F float D 表示 double M 表示十进制但不是 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;

这篇关于如何在不强制转换的情况下指定简短的int文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆