Skip to content

Commit 1209d6d

Browse files
authored
update the article on the char type (#45060)
* 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
1 parent 6538280 commit 1209d6d

File tree

1 file changed

+11
-12
lines changed
  • docs/csharp/language-reference/builtin-types

1 file changed

+11
-12
lines changed

docs/csharp/language-reference/builtin-types/char.md

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
---
22
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
55
f1_keywords:
66
- "char"
77
- "char_CSharpKeyword"
88
helpviewer_keywords:
99
- "char data type [C#]"
10-
ms.assetid: b51cf4fb-124c-4067-af48-afbac122b228
1110
---
1211
# char (C# reference)
1312

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.
1514

16-
|Type|Range|Size|.NET type|
17-
|----------|-----------|----------|-------------------------|
18-
|`char`|U+0000 to U+FFFF|16 bit|<xref:System.Char?displayProperty=nameWithType>|
15+
| Type | Range | Size | .NET type |
16+
|--------|------------------|--------|-------------------------------------------------|
17+
| `char` | U+0000 to U+FFFF | 16 bit | <xref:System.Char?displayProperty=nameWithType> |
1918

2019
The default value of the `char` type is `\0`, that is, U+0000.
2120

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.
2322

2423
The [string](reference-types.md#the-string-type) type represents text as a sequence of `char` values.
2524

@@ -31,18 +30,18 @@ You can specify a `char` value with:
3130
- a Unicode escape sequence, which is `\u` followed by the four-symbol hexadecimal representation of a character code.
3231
- a hexadecimal escape sequence, which is `\x` followed by the hexadecimal representation of a character code.
3332

34-
[!code-csharp-interactive[char literals](snippets/shared/CharType.cs#Literals)]
33+
:::code language="csharp" interactive="try-dotnet-method" source="snippets/shared/CharType.cs" id="Literals":::
3534

3635
As the preceding example shows, you can also cast the value of a character code into the corresponding `char` value.
3736

3837
> [!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.
4039
>
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.
4241
4342
## Conversions
4443

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.
4645

4746
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`.
4847

0 commit comments

Comments
 (0)