Re: Function Warning - Null Reference

Tech-Archive recommends: Fix windows errors by optimizing your registry



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).


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.

Because of the above, the default value for an uninitialised string is
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






.



Relevant Pages

  • Re: Function Warning - Null Reference
    ... I did not say that string is a value type. ... Integer is 0, the default value for a DateTime is 01/01/0001, the default ... This is not for a standard reference type. ... I find it an insult to tell that a so long regular as Stephany does not ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Concept ? about Modules vs Classes
    ... Keep in mind that in dotNet for every reference type ... Public Class DataClass ... Public Shared Sub getdata(ByVal ds as Dataset, ByVal SQLString As ... String, ByVal TableName as String) ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Function Warning - Null Reference
    ... These include String, Integer, DateTime and Boolean ... A type implemented as a Class is usually called a reference type. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Datasets? Properties? Values?
    ... Although string is a reference type, .NET has already included handling on ... Passing a reference type by value is just passing a pointer ... Public Property RefDataset() As DataSet ... > Dim FormNumber As String ...
    (microsoft.public.dotnet.framework)
  • Re: Datasets? Properties? Values?
    ... Although string is a reference type, .NET has already included handling on ... Passing a reference type by value is just passing a pointer ... Public Property RefDataset() As DataSet ... > Dim FormNumber As String ...
    (microsoft.public.dotnet.framework.windowsforms)