char keyword in C#

C# char keyword: Here, we will find out about the char keyword in C#, what is char keyword, how to utilize it in C#?

C# char keyword

In C#, char is a keyword which is utilized to announce a variable that can store a character esteem (Unicode esteem) esteem between the scope of +U0000 to U+FFFF. char keyword is a pseudonym of System.Char.

It possesses 2 bytes (16 bits) in the memory.

Syntax:

    char variable_name = value;

It can store the character between the scope of Unicode +U0000 to +UFFFF.

C# code to exhibit an example of char keyword:

Here, we are pronouncing a char variable Chr, introducing it with the worth ‘X’ and printing its worth, 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

Leave a Comment

error: Alert: Content is protected!!