Vs String in .NET.

I was using developerfusion.com to convert a snippet of my C # code to VB.NET and I noticed that the String type was translated to [String].

I tried googling and searching SO to no avail, so I'll ask the community if there is a difference between [String] and String? And if so, what is the difference between them (?)?

+1


a source to share


4 answers


The converter may have done this because it didn't recognize the string type and thought it was a class defined in your code.

You can place parentheses around identifiers for keyword usage. You can create your own class [String]

that is different from the built-in class String

, but this can of course be easily confusing ...



Public Class [String]
   Public Value As Integer
End Class

Dim s As New [String]
s.Value = 42

      

+6


a source


In VB.Net, [], the surrounding word is used to allow the keyword to be used as a normal identifier. So using [String] means I want to identify something with the word String and not with a VB string.



+8


a source


The parentheses usually indicate a variable name using a reserved keyword. Have you specified String variables?

+1


a source


Brackets can be used in VB.NET to use VB.NET keywords as user-defined names. For example, you can create an Integer class even though VB.NET already has the Integer keyword:

Public Class [Integer]
End Class

      

Hope this clarifies!

+1


a source







All Articles