隐式类型转换在C# [英] Implicit Type cast in C#

查看:96
本文介绍了隐式类型转换在C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于隐式类型转换的问题

为什么在C#这种隐式类型转换的工作?我已经学会了隐code通常不起作用。

我在这里有一个code样品关于隐式类型转换

 的char c ='A';
 INT X = C;
 INT N = 5;
 INT答案= N * C;
 Console.WriteLine(答案);


解决方案

铸造会导致数据丢失。在这里,焦炭是16位和的 INT 是32位。所以剧组会发生而不丢失数据。

现实生活中的例子:我们可以把一个小的器皿放入一个大容器而不是相反没有外部的帮助。

I have a question about the implicit type conversion

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

解决方案

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.

这篇关于隐式类型转换在C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆