Re: What Does This Mean?
- From: "Cor Ligthert [MVP]" <notmyfirstname@xxxxxxxxx>
- Date: Tue, 12 Dec 2006 07:09:14 +0100
_Anon,
Nobody discuss that they can be handy. I do not believe that there is a
serious person who would give String another name even not somebody from who
is selling underwear.
Cor
"_AnonCoward" <abcdef@xxxxxxxxxx> schreef in bericht
news:yhqfh.5261$dD2.673@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Herman Jones" <HermanJones@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in
message news:6F3326FF-B08F-4729-A6AB-80AD27F9EA27@xxxxxxxxxxxxxxxx
:
: I found this statement in some sample code. It seems to be
: syntactically correct. What do the brackets around "String"
: mean?
:
: Dim sWork As [String] = "Some number of characters"
I don't see the point of using the brackets in this context. I checked
out the complete code you included in the other post and it compiles
just fine with or without the brackets. Just out of curiousity, I
compared both versions of the code in the ildasm utility and the vb
compiler emitted the exact same code. In this instance, the brackets
are meaningless. That said, brackets are quite useful. Indeed, they
are often necessary.
Let's say you have access to an email message class written in C#
which exposes the following Properties:
From
To
Subject
Body
If you were to declare an instance of this class in vb, you'd have a
problem because "To" is a vb keyword. The following would fail:
With New CSharpEmailMessageType
.From = "Me@xxxxxxxxxxxx"
.To = "You@xxxxxxxxxxxxxx"
.Subject = "Hello"
.Body = "World"
End With
This would not compile. To get around this, you would need to do the
following:
With New CSharpEmailMessageType
.From = "Me@xxxxxxxxxxxx"
.[To] = "You@xxxxxxxxxxxxxx"
.Subject = "Hello"
.Body = "World"
End With
Now the code would compile just fine. Brackets tell the compiler to
treat what would otherwise be a reserved keyword as any other code
element.
Another use I've personally found for the brackets is when I'm
generating throw away code. I don't post to this forum often, but
occasionally I will offer a code example to a question. In those
cases, I may post a complete example that will compile and run. For
example, I might do something like this:
=======================================
Option Strict
Imports Microsoft.VisualBasic
Imports System
Public Module [module]
Public Sub Main
Dim c As New [class]
Console.WriteLine(c.GetMessage)
End Sub
End Module
Public Class [class]
Public Function GetMessage() As String
Return "Hello World" & vbCrLf
End Function
End Class
=======================================
I defined a module and a class but really didn't want to waste time
trying to figure out a clever or relevant name for them, so I just
named them '[module]' and '[class]' and moved on from there.
Ralf
--
--
----------------------------------------------------------
* ^~^ ^~^ *
* _ {~ ~} {~ ~} _ *
* /_``>*< >*<''_\ *
* (\--_)++) (++(_--/) *
----------------------------------------------------------
There are no advanced students in Aikido - there are only
competent beginners. There are no advanced techniques -
only the correct application of basic principles.
.
- References:
- Re: What Does This Mean?
- From: _AnonCoward
- Re: What Does This Mean?
- Prev by Date: Re: Data Relations with DataTable Class
- Next by Date: Re: combobox datasource...
- Previous by thread: Re: What Does This Mean?
- Next by thread: component to show info
- Index(es):
Relevant Pages
|