Re: empty vs null
From: Matthew (matthew_wills_at_mlc.com.au)
Date: 03/31/04
- Next message: Terry Olsen: "SecurityPermission (Accessing remote registry key)"
- Previous message: Cynthia Lau[MSFT]: "Re: Newbie - ADO"
- In reply to: Bill McCarthy
: "Re: empty vs null" - Messages sorted by: [ date ] [ thread ]
Date: 30 Mar 2004 17:29:10 -0800
Bill,
Re:
> VB.NET simplifies a lot of this, by allowing you to check for both conditions
> using the equality operator. So code like If MyString = Nothing, checks for
> both empty and null string conditions.
My docs (VB.NET 1.0) state:
<quote>
By definition, any String, including the empty string (""), compares
greater than a null reference (Nothing in Visual Basic); and two null
references compare equal to each other.
Use the Compare and Equals methods to perform combined reference and
value comparisons of Object and String instances. The equality and
inequality relational operators are implemented with the Equals method
and can also be used to make reference and value comparisons.
</quote>
which seems to contradict your point above (though feel free to point
out my error in understanding if you believe it is consistent with
your point). But when I TRY what you say, you appear to be right...
So, my question is, how did you find your above statement to be true?
Trial and error? Some other documentation elsewhere?
Thanks
Matthew
"Bill McCarthy <no spam>" <bill_mcc @ iprimus.com.au> wrote in message news:<O9R#KBUFEHA.3404@TK2MSFTNGP10.phx.gbl>...
> Hi Juzan,
>
> An empty string is "" where a null string is a variable that is yet to be
> allocated.
> To understand this, you really need to understand reference types, which is what
> a string is. A reference type, is a type when the actual location is pointed to.
> So say you have a variable MyString. That variable will be pushed onto the
> stack when you are working with it. The value of that will be a pointer to the
> string type itself, which will reside on the heap. IF the string is empty, "",
> there will be a pointer to a location on the heap where there is the empty
> string "" (or zero length string) If the string is null, then there will be a
> zero pointer, that is, no location on the heap.
>
> VB.NET simplifies a lot of this, by allowing you to check for both conditions
> using the equality operator. So code like If MyString = Nothing, checks for
> both empty and null string conditions.
> If you want to check for the reference actually being null, you use the Is
> operator. So If MyString Is Nothing checks for the null case only.
>
>
> Bill.
>
>
> "juzan" <chris@hotmail.com> wrote in message
> news:ux9ALpTFEHA.2560@TK2MSFTNGP12.phx.gbl...
> > hi
> > what is the difference between an empty string and a null string?
> > thanx
> >
> >
- Next message: Terry Olsen: "SecurityPermission (Accessing remote registry key)"
- Previous message: Cynthia Lau[MSFT]: "Re: Newbie - ADO"
- In reply to: Bill McCarthy
: "Re: empty vs null" - Messages sorted by: [ date ] [ thread ]
Relevant Pages
|