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.


    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


chr: X
Type of chr: System.Char
Size of a char variable: 2

Comments and Discussions!

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.