Yes, a numeric literal is, by default, an int
unless you specify otherwise, for example a decimal can be declared using a M
var myDecimal = 0M;
F
for float, L
for long. But there isnt one for short
you just need to rely on a cast:
public short CardType { get; set; }
CardType = (short)0;
On your edit:
Its not matter of casting. I want to understand why 0 cannot be short by default?
Its not relevant - Integers have to be some data type by default, in this case they just default to an int
as per the Language specification
The type of an integer literal is determined as follows:
- If the literal has no suffix, it has the first of these types in which its value can be represented:
int
, uint
, long
, ulong
.
- If the literal is suffixed by
U
or u
, it has the first of these types in which its value can be represented: uint
, ulong
.
- If the literal is suffixed by
L
or l
, it has the first of these types in which its value can be represented: long
, ulong
.
- If the literal is suffixed by
UL
, Ul
, uL
, ul
, LU
, Lu
, lU
, or lu
, it is of type ulong
.