Why can't you do Point p = null? It says it is non-nullable, but why?
Why can't you do Point p = null? It says it is non-nullable, but why?
That's something you should really be asking Anders and his cohorts.
"What's up, Doc?"
"'Up' is a relative concept. It has no intrinsic value."
Point is a value type. It is a structure. Probably the most popular example in books when they are talking about the differences between reference and value types in c# :P
Use:
Code:System.Drawing.Point? Point = null;
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Yeah, haven't read any books for C#. Don't generally have a problem but I miss some small details.
So, what does the ? exactly do here? I guess it makes Point nullable, eh?
yeah, it allows valuetypes to have a 'null' state, which is particularly useful for databases. it adds 2 properties to the instance, for example:
Code:if (blah.IsValid) { // blah.Value }
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Why? It's much more convenient to write
thanCode:int? X = null;
Code:System.Nullable<int> X = null;
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Code://try //{ if (a) do { f( b); } while(1); else do { f(!b); } while(1); //}
Well, you're not forced to use it, and there are quite a bit of those "accomplishments" in the C# language that are optional. The entire linq set is optional syntactic sugar but I love it more than using extension methods and lambdas