There are several null
values.
One programming language that represents variables and memory in a pointer-based method (which includes C # links, although it hides some details) is "it doesn't point to anything."
Another means that "it does not matter."
With reference types, we often use the former to represent the latter. We could use string label = null
to mean "no meaningful label". It remains, however, that the point is what happens in terms of where in memory and what points to it. However, this is pretty damn useful, what a shame we couldn't do it with int
and DateTime
in C # 1.1
What Nullable<T>
suggests means to say "no meaningful value," but at a level below it is not null
in the same way as a null
string (unless indicated in the box). It was assigned a null value and it is null, so it is logically null and null in accordance with some other semantics, but it is not null in the difference "does not point to anything" between reference and type values.
It is only the attribute "does not point to anything" of the reference type that prevents you from invoking instance methods on it.
And in fact, even this is not entirely true. IL allows you to reference instance methods on a null reference, and if it does not interact with any fields, it will work. It cannot work if it (directly or indirectly) needs these fields because they do not exist in a null refernce, but it can call null.FineWithNull()
if this method has been defined as:
int FineWithNull() {
With C #, it was decided to prohibit this, but this is not the rule for all .NET (I think F # allows this, but I'm not sure, I know that unmanaged C ++ allowed this, and it was useful in some very rare cases).
Jon hanna
source share