Saturday, March 23, 2019 00:47

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.

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).

 

Comments

comments

Tags: , ,

Leave a Reply