Newbie help needed

  • Thread starter Thread starter Miffed
  • Start date Start date
M

Miffed

Can anyone please tell me the difference between:

Dim myarray As String() = {"abc", "def", "ghi"}

and

Dim myarray As [String]() = {"abc", "def", "ghi"} ' note square brackets

The latter appears in an o'reilly book, the former is what makes sense to
me. They both appear to be semantically the same when used.
 
Miffed,

Here are the brackets for in VBNet
Dim [String] As String() = {"abc", "def", "ghi"}
MessageBox.Show([String](0))

However it should be a fool who use it in this way

I hope this helps?

Cor
 
Yes but this compiles OK. It is not the identifier which is being prevented
from being confused with a reserved word. It is the Type

Dim myarray As [String]() = {"abc", "def", "ghi"}

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Use the following to email me

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Debug.WriteLine(ob("ufssz/cvsotAhsfbuTpmvujpotXjui/OFU", False))

End Sub

Private Function ob(ByVal email As String, ByVal inc As Boolean) As
String

Dim ch() As Char
Dim i As Int32
Dim stepValue As Int16

If inc Then stepValue = 1 Else stepValue = -1

ch = email.ToCharArray()

For i = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) + stepValue)
Next

Return New String(ch)

End Function


Time flies when you don't know what you're doing

Cor Ligthert said:
Miffed,

Here are the brackets for in VBNet
Dim [String] As String() = {"abc", "def", "ghi"}
MessageBox.Show([String](0))

However it should be a fool who use it in this way

I hope this helps?

Cor


Miffed said:
Can anyone please tell me the difference between:

Dim myarray As String() = {"abc", "def", "ghi"}

and

Dim myarray As [String]() = {"abc", "def", "ghi"} ' note square brackets

The latter appears in an o'reilly book, the former is what makes sense to
me. They both appear to be semantically the same when used.
 
Terry,

You mean something as this?

\\\
Public Class Terry
Public Shared Sub Main()
Dim [String] As New [String]
MessageBox.Show([String](0))
End Sub
End Class
Friend Class [String]
Private [String]() As String = _
{"abc", "def", "ghi"}
Default Public Overloads ReadOnly _
Property Item(ByVal index As Integer) As String
Get
Return [String](index)
End Get
End Property
End Class
///

Cor

"One Handed Man ( OHM - Terry Burns )"
Yes but this compiles OK. It is not the identifier which is being
prevented
from being confused with a reserved word. It is the Type

Dim myarray As [String]() = {"abc", "def", "ghi"}

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Use the following to email me

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Debug.WriteLine(ob("ufssz/cvsotAhsfbuTpmvujpotXjui/OFU", False))

End Sub

Private Function ob(ByVal email As String, ByVal inc As Boolean) As
String

Dim ch() As Char
Dim i As Int32
Dim stepValue As Int16

If inc Then stepValue = 1 Else stepValue = -1

ch = email.ToCharArray()

For i = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) + stepValue)
Next

Return New String(ch)

End Function


Time flies when you don't know what you're doing

Cor Ligthert said:
Miffed,

Here are the brackets for in VBNet
Dim [String] As String() = {"abc", "def", "ghi"}
MessageBox.Show([String](0))

However it should be a fool who use it in this way

I hope this helps?

Cor


Miffed said:
Can anyone please tell me the difference between:

Dim myarray As String() = {"abc", "def", "ghi"}

and

Dim myarray As [String]() = {"abc", "def", "ghi"} ' note square
brackets

The latter appears in an o'reilly book, the former is what makes sense to
me. They both appear to be semantically the same when used.
 
Miffed,
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.

Seeing as 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

Hope this helps
Jay
 
Yes thats right. Jay responded to this in a fairly complete way. But yes,
you are correct..

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Use the following to email me

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Debug.WriteLine(ob("ufssz/cvsotAhsfbuTpmvujpotXjui/OFU", False))

End Sub

Private Function ob(ByVal email As String, ByVal inc As Boolean) As
String

Dim ch() As Char
Dim i As Int32
Dim stepValue As Int16

If inc Then stepValue = 1 Else stepValue = -1

ch = email.ToCharArray()

For i = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) + stepValue)
Next

Return New String(ch)

End Function


Time flies when you don't know what you're doing

Cor Ligthert said:
Terry,

You mean something as this?

\\\
Public Class Terry
Public Shared Sub Main()
Dim [String] As New [String]
MessageBox.Show([String](0))
End Sub
End Class
Friend Class [String]
Private [String]() As String = _
{"abc", "def", "ghi"}
Default Public Overloads ReadOnly _
Property Item(ByVal index As Integer) As String
Get
Return [String](index)
End Get
End Property
End Class
///

Cor

"One Handed Man ( OHM - Terry Burns )"
Yes but this compiles OK. It is not the identifier which is being
prevented
from being confused with a reserved word. It is the Type

Dim myarray As [String]() = {"abc", "def", "ghi"}

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Use the following to email me

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Debug.WriteLine(ob("ufssz/cvsotAhsfbuTpmvujpotXjui/OFU", False))

End Sub

Private Function ob(ByVal email As String, ByVal inc As Boolean) As
String

Dim ch() As Char
Dim i As Int32
Dim stepValue As Int16

If inc Then stepValue = 1 Else stepValue = -1

ch = email.ToCharArray()

For i = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) + stepValue)
Next

Return New String(ch)

End Function


Time flies when you don't know what you're doing

Cor Ligthert said:
Miffed,

Here are the brackets for in VBNet
Dim [String] As String() = {"abc", "def", "ghi"}
MessageBox.Show([String](0))

However it should be a fool who use it in this way

I hope this helps?

Cor


"Miffed" <[email protected]>
Can anyone please tell me the difference between:

Dim myarray As String() = {"abc", "def", "ghi"}

and

Dim myarray As [String]() = {"abc", "def", "ghi"} ' note square
brackets

The latter appears in an o'reilly book, the former is what makes
sense
to
me. They both appear to be semantically the same when used.
 
Thanks for that. Can't understand why the author of the book used it though
when there was no such amiguity in his example. Am I right to assume that
..net will first look for a matching user-defined [string] and then fall back
on system.string if one is not found? Can't see how it would still work if
not.

Jay B. Harlow said:
Miffed,
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.

Seeing as 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

Hope this helps
Jay


Miffed said:
Can anyone please tell me the difference between:

Dim myarray As String() = {"abc", "def", "ghi"}

and

Dim myarray As [String]() = {"abc", "def", "ghi"} ' note square brackets

The latter appears in an o'reilly book, the former is what makes sense to
me. They both appear to be semantically the same when used.
 
Hi Terry,
Yes thats right. Jay responded to this in a fairly complete way. But yes,
you are correct..

I sand my sample before Jay's message showed up in my newsreader, not that I
say he used it, than he had referenced to it. We did it independently and I
was more answering you in this.

One of the most stupid samples I ever made, I would not use it for someone
who is new in this.

:-)

Cor
 
Thats cool. Thanks for your reply.

Cheers - OHM

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Use the following to email me

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Debug.WriteLine(ob("ufssz/cvsotAhsfbuTpmvujpotXjui/OFU", False))

End Sub

Private Function ob(ByVal email As String, ByVal inc As Boolean) As
String

Dim ch() As Char
Dim i As Int32
Dim stepValue As Int16

If inc Then stepValue = 1 Else stepValue = -1

ch = email.ToCharArray()

For i = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) + stepValue)
Next

Return New String(ch)

End Function


Time flies when you don't know what you're doing
 
Miffed,
Am I right to assume that
.net will first look for a matching user-defined [string] and then fall
back
on system.string if one is not found?
Correct, because System is normally imported via "Project - Properties -
Common Properties - Imports"!

If you did not have System under the (above) Project Imports and you did not
have Imports System at the top of your source file, then System.String would
not be found for [String], as [String] is treated equally as any other
identifier.

I rarely use [] on String as I do not redefined String as my sample below
showed. I will use [] on other keywords that I want to use a method
(Property, Sub, Function, Event) on a type.

For example:

Public Class IntegerRange
Public Start As Integer
Public [End] As Integer

Public Function Contains(value As Integer) As Boolean
End Class

End is a keyword, so I could not use it as the End point of the above Range
without the brackets. When I use the above type in a program, End is
normally a qualified name, so I normally don't need brackets.

Dim range As IntegerRange
range.Start = 100
range.End = 200

If range.Contains(50) Then
End if

Hope this helps
Jay

Miffed said:
Thanks for that. Can't understand why the author of the book used it
though
when there was no such amiguity in his example. Am I right to assume that
.net will first look for a matching user-defined [string] and then fall
back
on system.string if one is not found? Can't see how it would still work
if
not.

Jay B. Harlow said:
Miffed,
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.

Seeing as 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

Hope this helps
Jay


Miffed said:
Can anyone please tell me the difference between:

Dim myarray As String() = {"abc", "def", "ghi"}

and

Dim myarray As [String]() = {"abc", "def", "ghi"} ' note square
brackets

The latter appears in an o'reilly book, the former is what makes sense to
me. They both appear to be semantically the same when used.
 
Miffed,
Can't understand why the author of the book used it though
when there was no such amiguity in his example.
FWIW: I can't understand why authors use if for the example you showed
either.

Jay

Miffed said:
Thanks for that. Can't understand why the author of the book used it
though
when there was no such amiguity in his example. Am I right to assume that
.net will first look for a matching user-defined [string] and then fall
back
on system.string if one is not found? Can't see how it would still work
if
not.

Jay B. Harlow said:
Miffed,
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.

Seeing as 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

Hope this helps
Jay


Miffed said:
Can anyone please tell me the difference between:

Dim myarray As String() = {"abc", "def", "ghi"}

and

Dim myarray As [String]() = {"abc", "def", "ghi"} ' note square
brackets

The latter appears in an o'reilly book, the former is what makes sense to
me. They both appear to be semantically the same when used.
 
Jay,

Do you have a problem when I use (your) text and (my) sample bellow next
time to show when this question comes again? (as showed bellow)

Cor

Here is an explanation about brackets as used in VBNet made by Jay B. Harlow
for the newsgroup languages.vb
Beneath that is a sample from Cor Ligthert not for using but to show it
completly and how weird that can be.

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

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
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top