How to specify a short int literal without casting?

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

    There is no suffix for the short data type in C#. If you want an integer literal to be a short, you need to explicitly state the type and provide a literal that is in range.

    short s = 123;
    

提交回复
热议问题