Re: Function Warning - Null Reference
- From: "Nick Hall" <nickh@xxxxxxxxxxxxxxxxxx>
- Date: Fri, 12 Jan 2007 12:25:41 -0000
Great summary; however there are a couple of mistakes in what you say which
I should point out.
"Stephany Young" <noone@localhost> wrote in message
news:en2ivfeNHHA.5012@xxxxxxxxxxxxxxxxxxxxxxx
Without going into the why's and wherefore's, some types in .NET are
called value types. These include String, Integer, DateTime and Boolean
among others. These are usually implemented as a Structure rather than as
Class. A type implemented as a Class is usually called a reference type.
String is NOT a value type; it is a reference type. String is what's called
an immutable reference type (once created, the string will never change
value).
Because of the above, the default value for an uninitialised string is
In general, you can assing Nothing to a variable of a reference type and
that variable is considered to be unassigned.
When you assign Nothing to a variable of a value type, then, behind the
scenes, the default value for that particular value type is substituted.
The default value for a String is String.Empty, the default value for an
Integer is 0, the default value for a DateTime is 01/01/0001, the default
value for a Boolean is False and so on and so forth.
Nothing (null reference) not String.Empty. The difference is quite
important, as you will get a NullReferenceException if you attempt to do
anything with a string before it is assigned.
Hope this clarifies,
Nick Hall
.
- Follow-Ups:
- Re: Function Warning - Null Reference
- From: Cor Ligthert [MVP]
- Re: Function Warning - Null Reference
- From: Stephany Young
- Re: Function Warning - Null Reference
- References:
- Function Warning - Null Reference
- From: Terry
- Re: Function Warning - Null Reference
- From: Stephany Young
- Re: Function Warning - Null Reference
- From: lord . zoltar
- Re: Function Warning - Null Reference
- From: Terry
- Re: Function Warning - Null Reference
- From: Stephany Young
- Function Warning - Null Reference
- Prev by Date: Re: Function Warning - Null Reference
- Next by Date: Re: Function Warning - Null Reference
- Previous by thread: Re: Function Warning - Null Reference
- Next by thread: Re: Function Warning - Null Reference
- Index(es):
Relevant Pages
|