Home »
C# Tutorial
C# char Keyword with Example
In this tutorial, we will learn about the char keyword in C# (with Example), what is char keyword, how to use it in C#?
By IncludeHelp Last updated : April 04, 2023
C# char Keyword
In C#, char is a keyword which is used to declare a variable that can store a character value (Unicode value) value between the range of +U0000 to U+FFFF. char keyword is an alias of System.Char.
It occupies 2 bytes (16 bits) in the memory.
Syntax
char variable_name = value;
It can store the character between the range of Unicode +U0000 to +UFFFF.
Example of char keyword in C#
Here, we are declaring a char variable chr, initializing it with the value 'X' and printing its value, type and size of a char type variable.
using System;
using System.Text;
namespace ConsoleApplication3 {
class Program {
static void Main(string[] args) {
//char variable declaration
char chr = 'X';
//printing value
Console.WriteLine("chr: " + chr);
//printing type of variable
Console.WriteLine("Type of chr: " + chr.GetType());
//printing size of a bool
Console.WriteLine("Size of a char variable: " + sizeof(char));
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output
chr: X
Type of chr: System.Char
Size of a char variable: 2