How to specify a short int literal without casting?

前端 未结 6 1530
温柔的废话
温柔的废话 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:48

    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;
    

提交回复
热议问题