You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: standard/lexical-structure.md
+97-8Lines changed: 97 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -616,34 +616,87 @@ The type of a *boolean_literal* is `bool`.
616
616
617
617
#### 6.4.5.3 Integer literals
618
618
619
-
Integer literals are used to write values of types `int`, `uint`, `long`, and `ulong`. Integer literals have two possible forms: decimal and hexadecimal.
619
+
Integer literals are used to write values of types `int`, `uint`, `long`, and `ulong`. Integer literals have three possible forms: decimal and, hexadecimal, and binary.
The type of an integer literal is determined as follows:
@@ -662,20 +715,41 @@ To permit the smallest possible `int` and `long` values to be written as integer
662
715
- When an *Integer_Literal* representing the value `2147483648` (2³¹) and no *Integer_Type_Suffix* appears as the token immediately following a unary minus operator token ([§11.8.3](expressions.md#1183-unary-minus-operator)), the result (of both tokens) is a constant of type int with the value `−2147483648` (−2³¹). In all other situations, such an *Integer_Literal* is of type `uint`.
663
716
- When an *Integer_Literal* representing the value `9223372036854775808` (2⁶³) and no *Integer_Type_Suffix* or the *Integer_Type_Suffix*`L` or `l` appears as the token immediately following a unary minus operator token ([§11.8.3](expressions.md#1183-unary-minus-operator)), the result (of both tokens) is a constant of type `long` with the value `−9223372036854775808` (−2⁶³). In all other situations, such an *Integer_Literal* is of type `ulong`.
664
717
718
+
> *Example*:
719
+
>
720
+
> ```csharp
721
+
>123// decimal, int
722
+
>10_543_765Lu// decimal, ulong
723
+
>1_2__3___4____5// decimal, int
724
+
>
725
+
>0xFf// hex, int
726
+
>0X1b_a0_44_fEL// hex, long
727
+
>0x1ade_3FE1_29AaUL// hex, ulong
728
+
>0x_abc// hex, int
729
+
>0xabc_// invalid; no trailing _ allowed
730
+
>
731
+
>0b101// binary, int
732
+
>0B1001_1010u// binary, uint
733
+
>0b1111_1111_0000UL// binary, ulong
734
+
>0B__111// binary, int
735
+
> ```
736
+
>
737
+
>*endexample*
738
+
665
739
#### 6.4.5.4 Real literals
666
740
667
741
Realliteralsareusedtowritevaluesoftypes `float`, `double`, and `decimal`.
@@ -706,6 +780,21 @@ The value of a real literal of type `float` or `double` is determined by using t
706
780
707
781
> *Note*: In a real literal, decimal digits are always required after the decimal point. For example, `1.3F` is a real literal but `1.F` is not. *end note*
708
782
783
+
> *Example*:
784
+
>
785
+
> ```csharp
786
+
>1.234_567// double
787
+
>.3e5f// float
788
+
>2_345E-2_0// double
789
+
>15D// double
790
+
>19.73M// decimal
791
+
>1.F// invalid; ill-formed (parsed as "1." and "F")
792
+
>1.234_// invalid; no trailing _ allowed in fraction
793
+
>.3e5_F// invalid; no trailing _ allowed in exponent
0 commit comments