Is listing char to work safely in C #?

Given the following code:

string source = "Some Unicode String";
foreach( char value in source ) {

    int y = (int)value;

}

Is it possible that casting from char to int might fail (and under what circumstances)?

+5
source share
2 answers

Converting from charto intwill not be performed with any value char.

From . Link NET 4.0

.NET Framework Char Unicode . Unicode 21- , , UTF-16, , 16- . 16- hexadecimal 0x0000 0xFFFF Char. Char - 16- () .

+8

, , . A char 0x0 0xFFFF (65535), int -2,147,483,648 2,147,483,647, char int.

+8

All Articles