什么是这段代码的含义(webrequest相关) [英] whats the meaning of this code (webrequest related)

查看:69
本文介绍了什么是这段代码的含义(webrequest相关)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

httpwebrequest request =(httpwebrequest).webrequest.create(http://yahoo.com)





现在,为了创建类的对象,我们做类似的事情



webform f2 = new webform();

f2.method()



上面的代码是某种类型的快捷方式还是其他我不知道的东西?



谢谢

httpwebrequest request = (httpwebrequest).webrequest.create("http://yahoo.com")


now, to create object of the class, we do something like

webform f2 = new webform();
f2.method()

the above code is shortcut of some kind or it is comething else which i dont know yet?

Thanks

推荐答案

意思是,它是类型转换:

Meaning is, it is type conversion :
引用:

类型转换基本上是类型转换或将一种类型的数据转换为另一种类型

Type conversion is basically type casting or converting one type of data to another type



首先,它是一个错误的代码。 (在投射方法后你有'。'

httpwebrequest request =(httpwebrequest).webrequest.create(http://yahoo.com);



其次,

WebRequest.Create 初始化一个新的 WebRequest 。因此你不必在这里施放方法。



我们做类型转换因为,

因为C#在编译时是静态类型的,所以在声明变量之后,它不能再次声明或用于存储另一种类型的值,除非该类型可以转换为变量的类型。例如,没有从整数到任意字符串的转换。因此,在将i声明为整数后,您不能将字符串Hello分配给它,如下面的代码所示。

请参阅,


And First, it is a wrong code. (You're having '.' after casting the method)
httpwebrequest request = (httpwebrequest).webrequest.create("http://yahoo.com");

Second,
WebRequest.Create Initializes a new WebRequest. Therefore you don't have to cast the method here.

We do the type casting because,
Because C# is statically-typed at compile time, after a variable is declared, it cannot be declared again or used to store values of another type unless that type is convertible to the variable's type. For example, there is no conversion from an integer to any arbitrary string. Therefore, after you declare i as an integer, you cannot assign the string "Hello" to it, as is shown in the following code.
See,

int i;
i = "Hello"; // Error: "Cannot implicitly convert type 'string' to 'int'"





您可以在初学者教程 - 用C#输入类型转换和类型转换 [ ^ ]和 MSDN [ ^ ]



-KR



You can find more info on A Beginner's Tutorial - Type Casting and Type Conversion in C#[^] and on MSDN[^]

-KR


这是复杂的方式来解释一个小文本框! :笑:

从这里开始: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(v = vs.110).aspx [ ^ ]

及时你已经读过(以及大多数链接)转到这里:如何在.NET中使用HttpWebRequest和HttpWebResponse [ ^ ]
It's way, way to complex to explain in a little textbox! :laugh:
Start here: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest(v=vs.110).aspx[^]
and when you've read that (and most of the links) move on to here: How to use HttpWebRequest and HttpWebResponse in .NET[^]


这篇关于什么是这段代码的含义(webrequest相关)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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