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
* update the article on the char type
Fixes#45049.
In addition add implicit conversion to `nint` and `nuint`.
Finally, perform an edit pass.
* build issue
Copy file name to clipboardExpand all lines: docs/csharp/language-reference/builtin-types/char.md
+11-12Lines changed: 11 additions & 12 deletions
Original file line number
Diff line number
Diff line change
@@ -1,25 +1,24 @@
1
1
---
2
2
description: Learn about the built-in character type in C#
3
-
title: "char type"
4
-
ms.date: 05/11/2020
3
+
title: "The char type"
4
+
ms.date: 02/27/2025
5
5
f1_keywords:
6
6
- "char"
7
7
- "char_CSharpKeyword"
8
8
helpviewer_keywords:
9
9
- "char data type [C#]"
10
-
ms.assetid: b51cf4fb-124c-4067-af48-afbac122b228
11
10
---
12
11
# char (C# reference)
13
12
14
-
The `char` type keyword is an alias for the .NET <xref:System.Char?displayProperty=nameWithType> structure type that represents a Unicode UTF-16 character.
13
+
The `char` type keyword is an alias for the .NET <xref:System.Char?displayProperty=nameWithType> structure type that represents a Unicode UTF-16 code unit, typically a UTF-16 character.
|`char`|U+0000 to U+FFFF|16 bit|<xref:System.Char?displayProperty=nameWithType>|
19
18
20
19
The default value of the `char` type is `\0`, that is, U+0000.
21
20
22
-
The `char` type supports [comparison](../operators/comparison-operators.md), [equality](../operators/equality-operators.md), [increment](../operators/arithmetic-operators.md#increment-operator-), and [decrement](../operators/arithmetic-operators.md#decrement-operator---) operators. Moreover, for `char` operands, [arithmetic](../operators/arithmetic-operators.md) and [bitwise logical](../operators/bitwise-and-shift-operators.md) operators perform an operation on the corresponding character codes and produce the result of the`int`type.
21
+
The `char` type supports [comparison](../operators/comparison-operators.md), [equality](../operators/equality-operators.md), [increment](../operators/arithmetic-operators.md#increment-operator-), and [decrement](../operators/arithmetic-operators.md#decrement-operator---) operators. Moreover, for `char` operands, [arithmetic](../operators/arithmetic-operators.md) and [bitwise logical](../operators/bitwise-and-shift-operators.md) operators perform an operation on the corresponding code points and produce the result as an`int`value.
23
22
24
23
The [string](reference-types.md#the-string-type) type represents text as a sequence of `char` values.
25
24
@@ -31,18 +30,18 @@ You can specify a `char` value with:
31
30
- a Unicode escape sequence, which is `\u` followed by the four-symbol hexadecimal representation of a character code.
32
31
- a hexadecimal escape sequence, which is `\x` followed by the hexadecimal representation of a character code.
As the preceding example shows, you can also cast the value of a character code into the corresponding `char` value.
37
36
38
37
> [!NOTE]
39
-
> In the case of a Unicode escape sequence, you must specify all four hexadecimal digits. That is, `\u006A` is a valid escape sequence, while `\u06A` and `\u6A` are not valid.
38
+
> In a Unicode escape sequence, you must specify all four hexadecimal digits. That is, `\u006A` is a valid escape sequence, while `\u06A` and `\u6A` are invalid.
40
39
>
41
-
> In the case of a hexadecimal escape sequence, you can omit the leading zeros. That is, the `\x006A`, `\x06A`, and `\x6A` escape sequences are valid and correspond to the same character.
40
+
> In a hexadecimal escape sequence, you can omit the leading zeros. That is, the `\x006A`, `\x06A`, and `\x6A` escape sequences are valid and correspond to the same character.
42
41
43
42
## Conversions
44
43
45
-
The `char` type is implicitly convertible to the following [integral](integral-numeric-types.md) types: `ushort`, `int`, `uint`, `long`, and `ulong`. It's also implicitly convertible to the built-in [floating-point](floating-point-numeric-types.md) numeric types: `float`, `double`, and `decimal`. It's explicitly convertible to `sbyte`, `byte`, and `short` integral types.
44
+
The `char` type is implicitly convertible to the following [integral](integral-numeric-types.md) types: `ushort`, `int`, `uint`, `long`, `ulong`, `nint`, and `nuint`. It's also implicitly convertible to the built-in [floating-point](floating-point-numeric-types.md) numeric types: `float`, `double`, and `decimal`. It's explicitly convertible to `sbyte`, `byte`, and `short` integral types.
46
45
47
46
There are no implicit conversions from other types to the `char` type. However, any [integral](integral-numeric-types.md) or [floating-point](floating-point-numeric-types.md) numeric type is explicitly convertible to `char`.
0 commit comments