简体   繁体   English

在这个字符串中,vb.net中的方形刹车是什么意思

[英]what do the square brakets mean in vb.net in this string

What do the square brakets mean in vb.net in this variable below defining as [String] 在vb.net中,以下定义为[String]的平方制动意味着什么?

Dim client As New WebClient()
Dim htmlCode As [String] = client.DownloadString("http://www.stackoverflow.com")

It's useless in your example. 在您的示例中没有用。 Brackets are there to use reserved keywords for what they aren't, for example 方括号用于使用保留关键字而不是保留关键字,例如

Dim [String] = "asdf"

which will create a var named "String" (which is stupid, but...) 这将创建一个名为“ String”的变量(这很愚蠢,但是...)

It allows you to use a reserved word in your code. 它允许您在代码中使用保留字。 There is some mis-information about this as some examples on the MS site use square brackets where they are not needed (In the example you gave the square brackets do not do anything) 对此有一些误导,因为MS站点上的某些示例在不需要的地方使用方括号(在示例中,您给方括号没有任何作用)

As an example I recently wanted to use lat and long as arguments to a function: 例如,我最近想使用latlong作为函数的参数:

Public Function CalcPosition(ByVal lat as Double, ByVal long as Double) as Double

This will not compile because Long is a reserved word but I can do this instead: 由于Long是保留字,因此无法编译,但是我可以这样做:

Public Function CalcPosition(ByVal lat as Double, ByVal [long] as Double) as Double

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM