How to specify a short int literal without casting?

前端 未结 6 1573
温柔的废话
温柔的废话 2020-12-15 02:20

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

va         


        
6条回答
  •  孤街浪徒
    2020-12-15 02:53

    Two options; neither ideal:

    1. Remove the var, specifying the type explicitly:

      short s = 123;
      
    2. Use the cast syntax (noting that this is a compile-time operation, not run-time):

      var s = (short)123;
      

    That's the only options for specifying a literal short.

提交回复
热议问题