I'm wondering what the difference is when declaring variables as such...
Dim something as String = Nothing
and
Dim something as [String] = String.Empty
Specifically the difference between String and [String].
There is no difference, apart from the fact that the first is Nothing
and the second is an empty string
.
You use the square brackets([...]
) around an identifier in VB.NET
to tell the compiler that it should ignore a keyword.
It is often used on Enum
:
Dim colors = [Enum].GetValues(GetType(Colors))
since Enum
is a keyword and a type. Without the brackets that wouldn't compile.
MSDN:
Regular identifiers may not match keywords, but escaped identifiers can. An escaped identifier is an identifier delimited by square brackets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With