Re: Function Warning - Null Reference
- From: "Scott M." <s-mar@xxxxxxxxxxxxx>
- Date: Sat, 13 Jan 2007 09:33:30 -0500
I have to disagree Cor. I think it was clear the Stephany was indicating
that a String is a Value Type and, as Tom pointed out, it is not. I don't
know how you could read the statement below and confuse her description as
anything but examples of what value type and reference types are. Also,
given her tone about how important terminology is, I think it was clear she
wasn't being anything esle but direct.
"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."
"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"
"Cor Ligthert [MVP]" <notmyfirstname@xxxxxxxxx> wrote in message
news:%23zrZ%23wsNHHA.3288@xxxxxxxxxxxxxxxxxxxxxxx
Nick,
There is in my idea a mistakes in your reply to Stephanie.
She is not writing a string *is* a value. She writes a string is *called*
a value type. That is often done, a string acts almost completely as a
value type.
As you wrote is a string is declared it has no reference and Is therefore
Nothing, as soon however that it is used in an operation it get a value
and = than Nothing. This standard assignment is only with strings.
Cor
"Nick Hall" <nickh@xxxxxxxxxxxxxxxxxx> schreef in bericht
news:eMwXHTkNHHA.448@xxxxxxxxxxxxxxxxxxxxxxx
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
- 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
- Re: Function Warning - Null Reference
- From: Nick Hall
- Re: Function Warning - Null Reference
- From: Cor Ligthert [MVP]
- Function Warning - Null Reference
- Prev by Date: Logical Mistake
- Next by Date: Re: Enum
- Previous by thread: Re: Function Warning - Null Reference
- Next by thread: Re: Function Warning - Null Reference
- Index(es):
Relevant Pages
|