使用不同类型的铸件 [英] use different types of casting

查看:72
本文介绍了使用不同类型的铸件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是强制转换,什么类型的强制转换以及如何在程序中使用.我想要.告诉我铸件的使用方法.请解释.举一个合适的例子

what is casting and how many types of casting and how i can use in my program. i want to. tell me the way to use the casting . please explain. with the suitable example

推荐答案

我很难相信你已经在google上找到了.使用这个出色的工具,我在几秒钟内获得了1,820,000个结果.第一个链接就是这个链接.
铸造(C#) [
I have a hard time believing that you have looked at google for this. Using this wonderful tool, I got 1,820,000 results in seconds. The very first link was this one.
Casting(C#)[^]


存在两种类型的类型转换,显式和隐式.
例如. int float 是隐式的,反之亦然.
明确是在强制强制转换时.
此处阅读更多信息 [
Two types of casts, explicit and implicit exist.
E.g. int to float is implicit but vice-versa is explicit.
Explicit is when you are forcing a cast.
Read more about this here[^].


这是一个广泛而笼统的问题,我建议您先阅读铸造的基础知识,然后将转换"与转换:"相比较,然后在此处提出更具体的问题.在最基本的层次上:使用广播"将一种类型转换为另一种类型;这很简单,但是我会用转换:"来说,您正在将一种类型的值转换为另一种类型的值.

您可以从以下CP文章开始:[
^ ],然后继续阅读这些MSDN资源中的广泛内容:[
This is such a broad, and general, question that I suggest you first read-up on the basics of casting, and "casting" compared to "conversion:" and then ask a more specific question here. At the most basic level: using ''casting'' you are transforming one Type into another; this is simplistic, but I''d say with "conversion:" you are transforming a value of one Type into a value of another Type.

You might start here with this CP article: [^], and then move on to read the broad content in these MSDN resources: [^], and [^].

You are going to need to learn why this does not work:
string someString = "100.0";
double someDouble = (double)someString; //compile error

但是,它确实可以做到:

But, this does:

double someDouble = Convert.ToDouble(someString);

当您准备好研究使用"as"运算符进行转换时:请务必阅读以下内容:[
如果您对广播"有基本的了解,那么我建议您承担学习将广播"用于接口的任务,这是一个高级主题,但功能强大的工具...对于某些重要功能而言是必需的诸如提出通知"之类的技术……对于传递对象实例非常有价值,因为该对象实例被强制转换为接口,因此将其内部内容的有限子集公开给该对象所传递的其他对象.

Bill,祝你好运

As you are ready to study the use of the ''as'' operator for casting: be sure and read this:[^]. The "as" operator can only be used with Reference Types and Nullable Types: and you need to learn what those are.

When you have a strong foundation in basic understanding of "casting," then I suggest you take on the task of learning to use "casting" to an Interface, which is an advanced topic, but a powerful tool ... necessary for some important techniques like raising "notifications" ... valuable for passing an instance of an object which, because it is cast to an Interface, exposes a limited subset of its internal contents to other objects it is passed to.

good luck, Bill


这篇关于使用不同类型的铸件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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