By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,257 Members | 928 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,257 IT Pros & Developers. It's quick & easy.

Shared Sub Connect(server As [String], message As [String]) ?

P: n/a
Question about

Shared Sub Connect(server As [String], message As [String])

Why is [String] in square brackets?

Is it like

Shared Sub Connect(server() As String, message() As String)

If so, is there any difference at all?

Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Again, the square brackets are not needed unless you are trying to avoid a
conflict of types names

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Emilio" <[void]> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Question about

Shared Sub Connect(server As [String], message As [String])

Why is [String] in square brackets?

Is it like

Shared Sub Connect(server() As String, message() As String)

If so, is there any difference at all?

Nov 21 '05 #2

P: n/a
Emilio

Here is an explanation about brackets as used in VBNet made by Jay B. Harlow
for the newsgroup languages.vb some days ago. Beneath that is a sample from
me not for using but to show it completly and to show how weird that can be.
In your sample it is useless to use brackets, except when String is a
special class.

Start of Jay B's text
-----
The brackets allow you to use a Keyword as an identifier. The first is using
String as a keyword, the second is using String specifically as an
identifier.

When brackets are used for a string than the String keyword in VB.NET is
simply an alias for System.String, and System is normally always imported,
you are correct they are semantically identical.

The only time that they would not be semantically identical is if you
defined a String type in your project.
\\\
Public Class [String]
End Class
///

In this case the brackets are required as I am using String as an
identifier. The String keyword would continue to be a keyword, an alias to
System.String, while [String] would be an identifier to my String class.
\\\
Dim a As [String] ' defines a MyProject.String variable
Dim b As String ' defines a System.String variable

If a = b Then ' fails as MyProject.String cannot be compared to
System.String
End If

---Start of my sample
To show how weird this can be when used
\\\
Public Class Weird
Public Shared Sub Main()
Dim [String] As New [String]
MessageBox.Show([String](0))
End Sub
End Class
Friend Class [String]
Private [String]() As String = _
{"Jay", "Cor", "Terry"}
Default Public Overloads ReadOnly _
Property Item(ByVal index As Integer) As String
Get
Return [String](index)
End Get
End Property
End Class
///
I hope this helps a little bit?

Cor

"Emilio" <[void]>
Question about

Shared Sub Connect(server As [String], message As [String])

Why is [String] in square brackets?

Is it like

Shared Sub Connect(server() As String, message() As String)

If so, is there any difference at all?

Nov 21 '05 #3

P: n/a
Can you explain why they use this syntax in the TcpClient overview
in the help pages? i.e.

Shared Sub Connect(server As [String], message As [String])
Try
' Create a TcpClient.
' Note, for this client to work you need to have a TcpServer
' connected to the same address as specified by the server, port
' combination.
Dim port As Int32 = 13000
Dim client As New TcpClient(server, port)

' Translate the passed message into ASCII and store it as a Byte
array.
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(message)

' Get a client stream for reading and writing.
' Stream stream = client.GetStream();
Dim stream As NetworkStream = client.GetStream()

' Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length)

Console.WriteLine("Sent: {0}", message)

' Receive the TcpServer.response.
' Buffer to store the response bytes.
data = New [Byte](256) {}

' String to store the response ASCII representation.
Dim responseData As [String] = [String].Empty

' Read the first batch of the TcpServer response bytes.
Dim bytes As Int32 = stream.Read(data, 0, data.Length)
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
Console.WriteLine("Received: {0}", responseData)

' Close everything.
client.Close()
Catch e As ArgumentNullException
Console.WriteLine("ArgumentNullException: {0}", e)
Catch e As SocketException
Console.WriteLine("SocketException: {0}", e)
End Try

Console.WriteLine(ControlChars.Cr + " Press Enter to continue...")
Console.Read()
End Sub 'Connect

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:eF**************@TK2MSFTNGP09.phx.gbl...
Again, the square brackets are not needed unless you are trying to avoid a
conflict of types names

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Emilio" <[void]> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Question about

Shared Sub Connect(server As [String], message As [String])

Why is [String] in square brackets?

Is it like

Shared Sub Connect(server() As String, message() As String)

If so, is there any difference at all?



Nov 21 '05 #4

P: n/a
The probability is that this code was ported from C++ or something or there
are other parts of the code which are not show but would have caused a
conflict.

Have you tried the example without the brackets ?
--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Emilio" <[void]> wrote in message
news:u5**************@TK2MSFTNGP12.phx.gbl...
Can you explain why they use this syntax in the TcpClient overview
in the help pages? i.e.

Shared Sub Connect(server As [String], message As [String])
Try
' Create a TcpClient.
' Note, for this client to work you need to have a TcpServer
' connected to the same address as specified by the server, port
' combination.
Dim port As Int32 = 13000
Dim client As New TcpClient(server, port)

' Translate the passed message into ASCII and store it as a Byte
array.
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(message)

' Get a client stream for reading and writing.
' Stream stream = client.GetStream();
Dim stream As NetworkStream = client.GetStream()

' Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length)

Console.WriteLine("Sent: {0}", message)

' Receive the TcpServer.response.
' Buffer to store the response bytes.
data = New [Byte](256) {}

' String to store the response ASCII representation.
Dim responseData As [String] = [String].Empty

' Read the first batch of the TcpServer response bytes.
Dim bytes As Int32 = stream.Read(data, 0, data.Length)
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
Console.WriteLine("Received: {0}", responseData)

' Close everything.
client.Close()
Catch e As ArgumentNullException
Console.WriteLine("ArgumentNullException: {0}", e)
Catch e As SocketException
Console.WriteLine("SocketException: {0}", e)
End Try

Console.WriteLine(ControlChars.Cr + " Press Enter to continue...")
Console.Read()
End Sub 'Connect

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:eF**************@TK2MSFTNGP09.phx.gbl...
Again, the square brackets are not needed unless you are trying to avoid a conflict of types names

--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--
"Emilio" <[void]> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Question about

Shared Sub Connect(server As [String], message As [String])

Why is [String] in square brackets?

Is it like

Shared Sub Connect(server() As String, message() As String)

If so, is there any difference at all?


Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.