Easy question about variable declarations

  • Thread starter Thread starter dev
  • Start date Start date
D

dev

Hi,
The following is from the documentation concerning a TCPClient class:

Dim responseData As [String] = [String].Empty

My question is: what do the brackets around '[String]' mean?

TIA,
Steve
 
Hi,
The following is from the documentation concerning a TCPClient class:

Dim responseData As [String] = [String].Empty

My question is: what do the brackets around '[String]' mean?

TIA,
Steve

In this particular case - they don't mean anything. They are simply
noise. I wish the MS samples would stop using them in these meaningless
cases since it just generates a lot of unnecessary questions...

What the brackets are supposed to do is let you use a Keyword as an
identifier. For example, many times you might want a class method named
stop...

Public Class ExampleClass
Public Sub Start()
' Do cool startup stuff
End Sub

Public Sub Stop()
' Do cool shutdown stuff
End Sub
End Sub

The problem is the above will not compile, because Stop is a VB.NET
keyword. But you can fix this easily...

Public Sub [Stop]()
...
End Sub

Now, the class will compile and can be used...
Dim ec As New ExampleClass()
ec.Start()
' do stuff
ec.Stop()


That's one simple example.

HTH
 
Please refer to the VB.Net documentation, would you please take a look at
that example and see if it makes more sense? Lookup the TCPClient Class
example. Thanks.

Herfried K. Wagner said:
* "dev said:
The following is from the documentation concerning a TCPClient class:

Dim responseData As [String] = [String].Empty

My question is: what do the brackets around '[String]' mean?

See:

<http://msdn.microsoft.com/library/en-us/vbls7/html/vblrfVBSpec2_2.asp>

The square brackets don't make sense in the sample you posted.
 
* "dev said:
Please refer to the VB.Net documentation, would you please take a look at
that example and see if it makes more sense? Lookup the TCPClient Class
example. Thanks.

The "[", "]" don't make sense in this sample.
 
Tom,
Thanks, I guess that's why I couldn't find any documentation for that
particular use of the brackets (around a variable) in the TCPClient class.
I'm fairly new to dotnet anyway which adds to my confusion. But I agree
with you, there is no reason for the meaningless noise in that sample.

Tom Shelton said:
Hi,
The following is from the documentation concerning a TCPClient class:

Dim responseData As [String] = [String].Empty

My question is: what do the brackets around '[String]' mean?

TIA,
Steve

In this particular case - they don't mean anything. They are simply
noise. I wish the MS samples would stop using them in these meaningless
cases since it just generates a lot of unnecessary questions...

What the brackets are supposed to do is let you use a Keyword as an
identifier. For example, many times you might want a class method named
stop...

Public Class ExampleClass
Public Sub Start()
' Do cool startup stuff
End Sub

Public Sub Stop()
' Do cool shutdown stuff
End Sub
End Sub

The problem is the above will not compile, because Stop is a VB.NET
keyword. But you can fix this easily...

Public Sub [Stop]()
...
End Sub

Now, the class will compile and can be used...
Dim ec As New ExampleClass()
ec.Start()
' do stuff
ec.Stop()


That's one simple example.

HTH
 
Back
Top