TheSwamp

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.

IOW the VB expression:
Code - vb.net: [Select]
  1. Dim pt As Point3d = Nothing
is equivalent to the C#
Code - C#: [Select]
  1. Point3d pt = new Point3d();
in both cases pt = (0,0,0)

So the VB expression
Code - vb.net: [Select]
  1. IsNothing(pt)
will always return False

PS: One more reason I hate VB...
Title: Re: Point3d == Null
Post by: huiz on May 31, 2015, 03:01:30 PM
Well thank you for explaining this gile. I didn't know that, I assumed Nothing was something as null.

I'm glad I switched from VB to C# 3 years ago, I don't feel sorry at all :-)