Difference between [Assembly] & Assembly [duplicate]
Possible Duplicate:
What does [String] mean in VB.NET?
Dim assem As [Assembly] = [Assembly].GetExecutingAssembly()
Dim assem As Assembly = Assembly.GetExecuti开发者_如何学编程ngAssembly()
Square braces in VB.NET are used to allow for literal naming, even if the identifier might be a keyword in VB.NET. Generally, these are more prevalent in generated code, since there's no point in doing it unless the word actually is a keyword.
In this case, there is no difference. What square braces allow you to do would be to, say, name a class the same as a keyword in VB.NET. For example,
Dim test as [Dim]
This would allow you to name your class Dim
, which would ordinarily give you an error since Dim
is a keyword.
Likewise, you can use it for variable names:
Dim [Dim] as String
Here, instead of on the type name, we're using it on the variable name. Same concept.
However, if you're doing this, then it's generally a code smell; it's usually a better idea to find a name that isn't a keyword so that people using your class don't have to enclose the name in braces.
精彩评论