Function Warning - Null Reference

  • Thread starter Thread starter Stephany Young
  • Start date Start date
System.DateTime is definitely a value type. That is because it is derived
from System.ValueType.

System.String is definitely NOT a value type. That is because it is NOT
derived from System.ValueType. Instead, it is derived directly from
System.Object.

For those who might be interested there is a fairly extensive of types that
are value type in the documentation. This can be found by locating
System.ValueType and then clicking on the Derived Classes link on that page.
 
Stephany

I did not say that string is a value type. I only am telling that it is not
acting like every other reference type.

Therefore I agree with your message because of this statement you wrote.
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 Boolean is False and so on and so forth.

This is true,
dim a as string
a = nothing
result a is string.Empty

This is not for a standard reference type. And because that you wrote before
that:
Without going into the why's and wherefore's, some types in .NET are called
value types.

Is for me the message about the default values more important the the
complete syntactical truth of it.

However, I was probably expecting more methodical thought in the message
than there really was.

I hope that this declares as well the discussion for the OP.

Cor



It has
 
Cor,

DateTimes are Value Types, not reference types like Strings. Of all the
primitive .NET types, only Strings and Objects are reference types. All
others are value types.
 
Stephany,

I was responding to Cor, not you. I never said that you hadn't spotted your
mistake, nor did I imply that you didn't know that Strings were reference
types. I was simply responding to Cor, when he said that he believed that
you were not actually saying (originally) that Strings were value types. He
and I have been discussing your first post about Strings and value types,
not the corrected post(s) after that.
 
Cor,

Cor Ligthert said:
I did not say that string is a value type. I only am telling that it is
not acting like every other reference type.

Therefore I agree with your message because of this statement you wrote.


This is true,
dim a as string
a = nothing
result a is string.Empty

'a Is String.Empty' evaluates to 'False' and string variables are
initialized to the 'Nothing' reference by default, not 'String.Empty'!
'String' has typical reference-type behavior here.
 
Herfried,
'a Is String.Empty' evaluates to 'False' and string variables are
initialized to the 'Nothing' reference by default, not 'String.Empty'!
'String' has typical reference-type behavior here.

What do you want to say, do you mean that you have investigated today and
learned that today. I suppose not, otherwise I can sent you by mail what I
find about your message.

I know this already for a long time. Armin and Jay have had to many
discussions about this subject that I am not able to forget this. I am glad
that you know it now as well. Have a look at Interent with search keys
String Armin and Jay you can learn than a lot more

I had not the idea about that I did write that somewhere. You can call my
message about the datetime a mistake from me, that Stephany correctly
replied.

Cor
 
I certainly prompted a debate.

Going back to my copy of .NET Framework 2.0 App Dev Foundation Training Kit,
I find that under the list of 'Other value Types' there is System.DateTime,
whilst under 'Common Reference Types' is listed System.String.

I do understand the common pitfalls that a newcomer to .NET may make in
handling text data.

All of the replying posts have been interesting and of value, I shall keep
the 'watched' flag on them all so that I can reference them from time to
time :-)

All your help has now enabled me to get my conversion of a VBA project to
VB.NET started and already producing results, many thanks.

Regards
Terry
 
I'm glad you got something out of our little scrap :)

It's not just the 'newcomer' who can fall into the various traps. We
'old-hands' can still fall into them just as easily, usually with much
tearing of hair and gnashing of teeth.

Don't be 'scared off' from posting queries that you might have from time to
time.
 
Back
Top