What is this called?
double d1 = 0d; decimal d2 = 0L; float d3 = 0f;
And where can I find a reference of characters I can use? If I want to cast 0
to short
, which letter I need?
(Background: numbers that have the additional letters, like st, nd, rd, and th are called ordinals: 1st, 2nd, 3rd, and 4th. When you shrink the letters and elevate them, they're called superscript ordinals: 1st, 2nd, 3rd, and 4th.)
An alphanumeric character is one which is either alphabetic or numeric — that is, either a letter or a digit. As a noun, we can talk about alphanumerics for the collection of them, as I do here in this answer.
Notice the "f" and "m" after the numbers - it tells the compiler that we are assigning a float and a decimal value. Without it, C# will interpret the numbers as double, which can't be automatically converted to either a float or decimal.
Ordinal numbers may be written in English with numerals and letter suffixes: 1st, 2nd or 2d, 3rd or 3d, 4th, 11th, 21st, 101st, 477th, etc., with the suffix acting as an ordinal indicator. Written dates often omit the suffix, although it is nevertheless pronounced.
The best source is the C# specification, specifically section Literals.
The relevant bits:
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
.If no real_type_suffix is specified, the type of the real literal is
double
. Otherwise, the real type suffix determines the type of the real literal, as follows:
A real literal suffixed by F or f is of type
float
. […]A real literal suffixed by D or d is of type
double
. […]A real literal suffixed by M or m is of type
decimal
. […]
That means the letter (or letters) is called “suffix”. There is no way to represent short
this way, so you have to use (short)0
, or just short x = 0;
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With