Saturday, May 21, 2022 19:22

Table of contents >> Introduction > Char variable type

Char variable type

C# language uses char variable type to store values of type character. The C# compiler allocates 16 bits (2 bytes) to store a char variable, which is similar to the ushort type. The char variable type can store integer value types ranging from 0 to 65535. The following image shows the representation of such a variable.

char variable type

You can assign values to char variables like this:

The second way of assigning a value to a char variable is casting an integer type into a char type (converting one variable type into another variable type).

Char variable type can only store one letter at a time. To store more characters, you have to declare a string which we will explain later.

The concepts explained in this lesson are also shown visually as part of the following video:

EXERCISES
1. Declare a variable of type char and assign it as a value the character which has Unicode code 72 (use the Windows calculator in order to find hexadecimal representation of 72).

 

Tags: ,

Leave a Reply



Follow the white rabbit