Skip to content

Latest commit

 

History

History
50 lines (42 loc) · 2.94 KB

File metadata and controls

50 lines (42 loc) · 2.94 KB
title char (C# Reference)
ms.date 07/20/2015
ms.prod .net
ms.technology
devlang-csharp
ms.topic article
f1_keywords
char
char_CSharpKeyword
helpviewer_keywords
char data type [C#]
ms.assetid b51cf4fb-124c-4067-af48-afbac122b228
caps.latest.revision 27
author BillWagner
ms.author wiwagn

char (C# Reference)

The char keyword is used to declare an instance of the xref:System.Char?displayProperty=nameWithType structure that the .NET Framework uses to represent a Unicode character. The value of a Char object is a 16-bit numeric (ordinal) value.

Unicode characters are used to represent most of the written languages throughout the world.

Type Range Size .NET Framework type
char U+0000 to U+FFFF Unicode 16-bit character xref:System.Char?displayProperty=nameWithType

Literals

Constants of the char type can be written as character literals, hexadecimal escape sequence, or Unicode representation. You can also cast the integral character codes. In the following example four char variables are initialized with the same character X:

[!code-csharpcsrefKeywordsTypes#19]

Conversions

A char can be implicitly converted to ushort, int, uint, long, ulong, float, double, or decimal. However, there are no implicit conversions from other types to the char type.

The xref:System.Char?displayProperty=nameWithType type provides several static methods for working with char values.

C# Language Specification

[!INCLUDECSharplangspec]

See Also

xref:System.Char
C# Reference
C# Programming Guide
C# Keywords
Integral Types Table
Built-In Types Table
Implicit Numeric Conversions Table
Explicit Numeric Conversions Table
Nullable Types
Strings