Home »
C#.Net
char keyword in C#
C# char keyword: Here, we are going to learn about the char keyword in C#, what is char keyword, how to use it in C#?
Submitted by IncludeHelp, on March 06, 2019
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.
C# code to demonstrate example of char keyword
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