Re: Function Warning - Null Reference



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
    ... These include String, Integer, DateTime and Boolean ... String is NOT a value type; it is a reference type. ...
    (microsoft.public.dotnet.languages.vb)
  • 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: 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.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)