且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

什么是这段代码的含义(webrequest相关)

更新时间:2021-08-13 15:27:00

意思是,它是类型转换:

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[^]