在C#中将char隐式转换为int

在C#中将char隐式转换为int

问题描述:

我对隐式类型转换有疑问

I have a question about the implicit type conversion

为什么这种隐式类型转换在C#中起作用?我知道隐式代码通常不起作用。

Why does this implicit type conversion work in C#? I've learned that implicit code usually don't work.

我这里有一个有关隐式类型转换的代码示例

I have a code sample here about implicit type conversion

 char c = 'a';
 int x = c;
 int n = 5;
 int answer = n * c;
 Console.WriteLine(answer);


铸造会导致数据丢失。此处 char 是16位,而 int 是32位。

Casting will cause data loss. Here char is 16 bit and int is 32 bit. So the cast will happen without loss of data.

现实生活中的例子:在没有外部帮助的情况下,我们可以将小型船只放入大型船只,反之亦然。

Real life example: we can put a small vessel into a big vessel but not vice versa without external help.