[String] [Boolean] [Integer] string Booleal Integer

Johnson

Well-known member
Joined
Mar 6, 2009
Messages
158
Programming Experience
Beginner
Why do some people wrap types inside of []? is it just a preference to coding or actually means any thing different?

VB.NET:
Private m_someString As [String] = [String].Empty

Can't find any thing on google.
 
If you want to use a VB keyword in your code in some context other than as a keyword then you have to wrap it in brackets. For instance, let's say that you want to declare two Date variables named 'start' and 'end':
Dim start As Date
Dim [end] As Date
In this case, 'start' is not a VB keyword so you can use it as you usually would but 'end' is a keyword so you must wrap it in brackets or a syntax error will occur.

String, Boolean and Integer are all VB keywords too. In your example, by wrapping the String in brackets, it will not be interpreted as a VB keyword. Instead it will be interpreted as the System.String class. The thing is, the inherent VB data type String is just an alias for the System.String class anyway, so it makes no actual difference. The same goes for the Boolean data type and the System.Boolean structure. Noone's going to escape the Integer keyword with brackets though, because the Integer data type is an alias for the System.Int32 structure.
 
Perfect sense. Nice One guys. I understand about the keywords and why you would do it but seems silly wrapping the actual type inside []
 
seems silly wrapping the actual type inside []
Indeed, doing so also affects the code syntax coloring in IDE, making it the color of a type name rather than the default color for keywords and built-in data types.
 
I agree too. I've seen that done in various code examples on the web and I have no idea why anyone would choose to do it. As far as I'm aware there is zero advantage so it seems completely pointless. While it's only marginal, I'd say that it makes the code harder to read too, so I think that the net result is a loss.
 
Back
Top