Code Red => .NET => Topic started by: shers on May 22, 2015, 02:02:44 AM
Title: Point3d == Null
Post by: shers on May 22, 2015, 02:02:44 AM
Hi,
How can I check if Point3d == Null?
Point3d InsPt;
If (InsPt == null) {
}
Thanks
Title: Re: Point3d == Null
Post by: gile on May 22, 2015, 03:46:22 AM
Hi,
As I tried to explain you here (http://www.theswamp.org/index.php?topic=49475.msg546159#msg546159), Point3d is a value type (as integers, doubles, etc.), and a value type cannot be null.
Please, read almost this thread (https://msdn.microsoft.com/en-us/library/s1ax56ch%28v=vs.90%29.aspx).
Title: Re: Point3d == Null
Post by: mohnston on May 28, 2015, 02:25:12 PM
If you would like to Point3d to be null you can declare it as nullable by adding a question mark (?).
Point3d? InsPt = null; InsPt = SomeFunctionThatMayOrMayNotSuccessfullyGetAPoint3d(); // Returns a Point3d? NOT a Point3d If (InsPt != null) { Point3d myPt = InsPt.Value; }
Title: Re: Point3d == Null
Post by: huiz on May 30, 2015, 09:17:53 AM
You can read more information about nullable types here: http://geekswithblogs.net/BlackRabbitCoder/archive/2012/07/12/c.net-little-wondres-the-nullablelttgt-struct.aspx
Weird but in VB.Net a Point3d can be null, but in C# not.
Title: Re: Point3d == Null
Post by: gile on May 30, 2015, 11:53:52 AM
Weird but in VB.Net a Point3d can be null, but in C# not.
Not exactly, the VB Nothing keyword isn't an equivalent of null C# keyword, it represents the default value which is effectively null for the reference types, but not for the non nullable value types.