隐式类型转换在C#

编程入门 行业动态 更新时间:2024-10-13 22:22:42
本文介绍了隐式类型转换在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#

本文发布于:2023-07-14 10:16:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1104081.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   隐式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!