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

对着背影说爱祢 提交于 2020-01-15 11:54:29

问题


What do the square brakets mean in vb.net in this variable below defining as [String]

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

回答1:


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...)




回答2:


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)

As an example I recently wanted to use lat and long as arguments to a function:

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:

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


来源:https://stackoverflow.com/questions/11574655/what-do-the-square-brakets-mean-in-vb-net-in-this-string

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!