Skip to content

Commit 6c4a21c

Browse files
CopilotBillWagnergewarren
authored
Add Unicode escape sequence scenario to CS1012 error documentation (#47962)
* Initial plan * Add Unicode escape sequence scenario to CS1012 error documentation Co-authored-by: BillWagner <[email protected]> * Update docs/csharp/misc/cs1012.md * Update docs/csharp/misc/cs1012.md * Update docs/csharp/misc/cs1012.md * Update docs/csharp/misc/cs1012.md Co-authored-by: Genevieve Warren <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: BillWagner <[email protected]> Co-authored-by: Bill Wagner <[email protected]> Co-authored-by: Genevieve Warren <[email protected]>
1 parent 22f92a1 commit 6c4a21c

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

docs/csharp/misc/cs1012.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ ms.assetid: 4acc5fe0-da47-4882-b7d8-557767d7cf03
1212

1313
Too many characters in character literal
1414

15-
An attempt was made to initialize a [char](../language-reference/builtin-types/char.md) constant with more than one character.
16-
17-
CS1012 can also occur when doing data binding. For example the following line will give an error:
15+
An attempt was made to initialize a [char](../language-reference/builtin-types/char.md) constant with more than one character. CS1012 can occur when doing data binding. CS1012 can also occur when using Unicode escape sequences that exceed the UTF-16 range. A character literal represents a single character as a UTF-16 code unit, so Unicode values greater than 0xFFFF (65535) aren't valid in character literals. For example, the following code gives an error:
1816

1917
`<%# DataBinder.Eval(Container.DataItem, 'doctitle') %>`
2018

@@ -30,9 +28,12 @@ class Sample
3028
{
3129
static void Main()
3230
{
33-
char a = 'xx'; // CS1012
34-
char a2 = 'x'; // OK
35-
System.Console.WriteLine(a2);
31+
char a = 'xx'; // CS1012 - too many characters
32+
char b = '\U00010000'; // CS1012 - exceeds UTF-16 range (> 0xFFFF)
33+
34+
char c = 'x'; // OK
35+
char d = '\u0061'; // OK - represents 'a' within UTF-16 range
36+
System.Console.WriteLine($"{c}, {d}");
3637
}
3738
}
3839
```

0 commit comments

Comments
 (0)