I'm using some sample code from MSDN. The code includes the following
statement:
Dim content as [String] = [String].Empty
I'm not familiar with the use of the square brackets. Can someone please
explain to me what the difference between "Dim content as [String]" and
"Dim content as String". Thanks.
Peter,
--
----------------------------------------------------
This mailbox protected from junk email by MailFrontier Desktop
from MailFrontier, Inc. http://info.mailfrontier.com 8 4817
I've seen square brackets used to allow variable names that match keywords,
but your example is definately odd.
Dim [String] As String = String.Empty
Greg
"Peter Merwood" <pe*****@circle-consulting.co.nz> wrote in message
news:ey**************@TK2MSFTNGP09.phx.gbl... I'm using some sample code from MSDN. The code includes the following statement:
Dim content as [String] = [String].Empty
I'm not familiar with the use of the square brackets. Can someone please explain to me what the difference between "Dim content as [String]" and "Dim content as String". Thanks.
Peter,
--
---------------------------------------------------- This mailbox protected from junk email by MailFrontier Desktop from MailFrontier, Inc. http://info.mailfrontier.com
Peter,
In the beginning of VBNet where most samples on MSDN translated C# or
translated VB classic ones. This becomes better and better, however there
are still some odd ones. And as Greg stated already this is one of them.
(You are not the first one who ask this question about that sample) Dim content as [String] = [String].Empty
This sample would imply that you have created your own class with the name
[String] and because there is already a String class, that would be
ambigious and you use the brackets to tell to use your own class.
As well it tells that you have created somewhere your own shared
String.Empty methode and for that obtains the same rules as above.
Only a lunatic will do that.
I hope this explains it something?
Cor
"Peter Merwood" <pe*****@circle-consulting.co.nz>
I'm using some sample code from MSDN. The code includes the following statement:
Dim content as [String] = [String].Empty
I'm not familiar with the use of the square brackets. Can someone please explain to me what the difference between "Dim content as [String]" and "Dim content as String". Thanks.
Peter,
--
---------------------------------------------------- This mailbox protected from junk email by MailFrontier Desktop from MailFrontier, Inc. http://info.mailfrontier.com
Cor
Thanks for the explanation. It all becomes clear now.
I'm not a "lunatic" (!) and I don't have any objects in my project named
"String". Therefore I'll change "Dim content as [String] = [String].Empty"
to "Dim content as String".
The use of the String.Empty initial value by MS is also a bit dumb - aren't
all strings empty by default when they're initialised?
Thanks again.
Peter
--
----------------------------------------------------
This mailbox protected from junk email by MailFrontier Desktop
from MailFrontier, Inc. http://info.mailfrontier.com
"Cor Ligthert" <no************@planet.nl> wrote in message
news:ez*************@TK2MSFTNGP15.phx.gbl... Peter,
In the beginning of VBNet where most samples on MSDN translated C# or translated VB classic ones. This becomes better and better, however there are still some odd ones. And as Greg stated already this is one of them. (You are not the first one who ask this question about that sample)
Dim content as [String] = [String].Empty
This sample would imply that you have created your own class with the name [String] and because there is already a String class, that would be ambigious and you use the brackets to tell to use your own class.
As well it tells that you have created somewhere your own shared String.Empty methode and for that obtains the same rules as above.
Only a lunatic will do that.
I hope this explains it something?
Cor
"Peter Merwood" <pe*****@circle-consulting.co.nz>
I'm using some sample code from MSDN. The code includes the following statement:
Dim content as [String] = [String].Empty
I'm not familiar with the use of the square brackets. Can someone
please explain to me what the difference between "Dim content as [String]" and "Dim content as String". Thanks.
Peter,
--
---------------------------------------------------- This mailbox protected from junk email by MailFrontier Desktop from MailFrontier, Inc. http://info.mailfrontier.com
Peter, The use of the String.Empty initial value by MS is also a bit dumb - aren't all strings empty by default when they're initialised?
As you said, however there is a slight difference the String is an forever
confusing value what can be an object.
With the String you have this
\\\
dim content as string
///
Gives with
If content Is Nothing then messagebox.show("true")
true
While
dim content as string = "" (what is a constant) does not give that.
They both give
If content = Nothing then messagebox.show("true")
true
There is a lot written in this newsgroup about this, so maybe you can google
this newsgroup for that when you want to know more.
However, I hope this gives some idea's?
Cor
"Peter Merwood"
Cor
Thanks for the explanation. It all becomes clear now.
I'm not a "lunatic" (!) and I don't have any objects in my project named "String". Therefore I'll change "Dim content as [String] = [String].Empty" to "Dim content as String".
The use of the String.Empty initial value by MS is also a bit dumb - aren't all strings empty by default when they're initialised?
Thanks again.
Peter --
---------------------------------------------------- This mailbox protected from junk email by MailFrontier Desktop from MailFrontier, Inc. http://info.mailfrontier.com
"Cor Ligthert" <no************@planet.nl> wrote in message news:ez*************@TK2MSFTNGP15.phx.gbl... Peter,
In the beginning of VBNet where most samples on MSDN translated C# or translated VB classic ones. This becomes better and better, however there are still some odd ones. And as Greg stated already this is one of them. (You are not the first one who ask this question about that sample)
>Dim content as [String] = [String].Empty
This sample would imply that you have created your own class with the name [String] and because there is already a String class, that would be ambigious and you use the brackets to tell to use your own class.
As well it tells that you have created somewhere your own shared String.Empty methode and for that obtains the same rules as above.
Only a lunatic will do that.
I hope this explains it something?
Cor
"Peter Merwood" <pe*****@circle-consulting.co.nz>
> I'm using some sample code from MSDN. The code includes the following > statement: > > Dim content as [String] = [String].Empty > > I'm not familiar with the use of the square brackets. Can someone please > explain to me what the difference between "Dim content as [String]" > and > "Dim content as String". Thanks. > > Peter, > > -- > > > ---------------------------------------------------- > This mailbox protected from junk email by MailFrontier Desktop > from MailFrontier, Inc. http://info.mailfrontier.com > >
"Peter Merwood" <pe*****@circle-consulting.co.nz> schrieb: Dim content as [String] = [String].Empty
I'm not familiar with the use of the square brackets. Can someone please explain to me what the difference between "Dim content as [String]" and "Dim content as String".
The square brackets are documented here:
<URL:http://msdn.microsoft.com/library/en-us/vbls7/html/vblrfVBSpec2_2.asp>
In the sample code you showed above, square brackets don't make much sense.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Peter, The use of the String.Empty initial value by MS is also a bit dumb - aren't all strings empty by default when they're initialised?
No, all strings are Nothing by default when they're initialized.
In addition to Cor's example. Try the following:
Dim content As String
If content.Length = 0 Then
' Never gets here
' as an NullReferenceException was raised!
End IF
VB considers a String variable that is Nothing and a String variable that
has String.Empty in it as equal.
Hope this helps
Jay
"Peter Merwood" <pe*****@circle-consulting.co.nz> wrote in message
news:%2****************@tk2msftngp13.phx.gbl... Cor
Thanks for the explanation. It all becomes clear now.
I'm not a "lunatic" (!) and I don't have any objects in my project named "String". Therefore I'll change "Dim content as [String] = [String].Empty" to "Dim content as String".
The use of the String.Empty initial value by MS is also a bit dumb - aren't all strings empty by default when they're initialised?
Thanks again.
Peter --
---------------------------------------------------- This mailbox protected from junk email by MailFrontier Desktop from MailFrontier, Inc. http://info.mailfrontier.com
"Cor Ligthert" <no************@planet.nl> wrote in message news:ez*************@TK2MSFTNGP15.phx.gbl... Peter,
In the beginning of VBNet where most samples on MSDN translated C# or translated VB classic ones. This becomes better and better, however there are still some odd ones. And as Greg stated already this is one of them. (You are not the first one who ask this question about that sample)
>Dim content as [String] = [String].Empty
This sample would imply that you have created your own class with the name [String] and because there is already a String class, that would be ambigious and you use the brackets to tell to use your own class.
As well it tells that you have created somewhere your own shared String.Empty methode and for that obtains the same rules as above.
Only a lunatic will do that.
I hope this explains it something?
Cor
"Peter Merwood" <pe*****@circle-consulting.co.nz>
> I'm using some sample code from MSDN. The code includes the following > statement: > > Dim content as [String] = [String].Empty > > I'm not familiar with the use of the square brackets. Can someone please > explain to me what the difference between "Dim content as [String]" > and > "Dim content as String". Thanks. > > Peter, > > -- > > > ---------------------------------------------------- > This mailbox protected from junk email by MailFrontier Desktop > from MailFrontier, Inc. http://info.mailfrontier.com > >
Jay,
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb: The use of the String.Empty initial value by MS is also a bit dumb - aren't all strings empty by default when they're initialised? No, all strings are Nothing by default when they're initialized.
That's true. Strings are initialized with 'Nothing', not 'String.Empty'.
In addition to Cor's example. Try the following:
Dim content As String If content.Length = 0 Then ' Never gets here ' as an NullReferenceException was raised! End IF
VB considers a String variable that is Nothing and a String variable that has String.Empty in it as equal.
Just to make sure that this is not misread: The code above won't throw an
exception if 'String.Empty' was assigned to 'content'. If this was the
case, 'content.Length' would return 0.
What VB does is considering a string variable that points to 'Nothing' and a
string variable that has 'String.Empty' in it as equal when comparing these
string variables using '=':
\\\
Dim s1 As String
Dim s2 As String = String.Empty
MsgBox(CStr(s1 = s2)) ' 'True'.
///
.... and...
\\\
Dim s1 As String
Dim s2 As String = String.Empty
MsgBox(CStr(s1 Is s2)) ' 'False'.
///
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Herfried, Just to make sure that this is not misread: The code above won't throw an exception if 'String.Empty' was assigned to 'content'. If this was the case, 'content.Length' would return 0.
Correct, I intentionally left off the initialization of the variable
"content", so it was initialized to its "default" value of Nothing.
Thanks for the additional.
Jay
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uD**************@TK2MSFTNGP09.phx.gbl... Jay,
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> schrieb: The use of the String.Empty initial value by MS is also a bit dumb - aren't all strings empty by default when they're initialised?
No, all strings are Nothing by default when they're initialized.
That's true. Strings are initialized with 'Nothing', not 'String.Empty'.
In addition to Cor's example. Try the following:
Dim content As String If content.Length = 0 Then ' Never gets here ' as an NullReferenceException was raised! End IF
VB considers a String variable that is Nothing and a String variable that has String.Empty in it as equal.
Just to make sure that this is not misread: The code above won't throw an exception if 'String.Empty' was assigned to 'content'. If this was the case, 'content.Length' would return 0.
What VB does is considering a string variable that points to 'Nothing' and a string variable that has 'String.Empty' in it as equal when comparing these string variables using '=':
\\\ Dim s1 As String Dim s2 As String = String.Empty MsgBox(CStr(s1 = s2)) ' 'True'. ///
... and...
\\\ Dim s1 As String Dim s2 As String = String.Empty MsgBox(CStr(s1 Is s2)) ' 'False'. ///
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Robin Tucker |
last post by:
Hi,
I would like to select records from a table where the following criteria
hold:
SELECT * from Mytable where
field x "contains" string @X
or
|
by: Indrid Colt |
last post by:
Thank's for your help !
Indrid
|
by: ondekoza |
last post by:
Hello,
I need to convert the string "FFFFFFFF" to a long. To convert this
string I tried the following:
>>> 0xffffffff
-1
>>> 0xffffffffL
4294967295L
OK, this is what I want, so I tried
|
by: pinkfloydhomer |
last post by:
How do I check if a string contains (can be converted to) an int? I
want to do one thing if I am parsing and integer, and another if not.
/David
|
by: Fei Liu |
last post by:
In Accellerated C++, the author recommends that in a header file one should
not declare
using std::string, using std::vector etc instead one should directly specify
the namespace specifier in...
|
by: excite |
last post by:
I am trying to write a long string into a txt file, the string includes some backslash, looks like:
'd:\#########\#######\####### d:\######\####\####\### d:\###\###\'
then I got a error saying...
|
by: Petyr David |
last post by:
Just looking for the simplest. right now my perl script returns an
error messge to the user if the date string is invalid. would like to
do this before accessing the server.
TX
|
by: lovecreatesbea... |
last post by:
Is it correct and safe to compare a string object with "", a pair of
quotation marks quoted empty string?If the string object: s = ""; does
s contain a single '\'? Is it better to use...
|
by: mato81 |
last post by:
Hi all!
I am a newbie to WSDL. I have a questions which has been driving me crazy...
If I would have a WSDL with a types element somewhat like below, what is the point of the third last row...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |