Author Topic: Point3d == Null  (Read 3628 times)

0 Members and 1 Guest are viewing this topic.

shers

  • Guest
Point3d == Null
« on: May 22, 2015, 02:02:44 AM »
Hi,

How can I check if Point3d == Null?

Point3d InsPt;

If (InsPt == null)
{

}

Thanks

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Point3d == Null
« Reply #1 on: May 22, 2015, 03:46:22 AM »
Hi,

As I tried to explain you here, Point3d is a value type (as integers, doubles, etc.), and a value type cannot be null.

Please, read almost this thread.
« Last Edit: May 22, 2015, 03:53:12 AM by gile »
Speaking English as a French Frog

mohnston

  • Bull Frog
  • Posts: 305
  • CAD Programmer
Re: Point3d == Null
« Reply #2 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;
}
It's amazing what you can do when you don't know what you can't do.
CAD Programming Solutions

huiz

  • Swamp Rat
  • Posts: 917
  • Certified Prof C3D
Re: Point3d == Null
« Reply #3 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.
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.

gile

  • Gator
  • Posts: 2507
  • Marseille, France
Re: Point3d == Null
« Reply #4 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...
« Last Edit: May 30, 2015, 12:03:58 PM by gile »
Speaking English as a French Frog

huiz

  • Swamp Rat
  • Posts: 917
  • Certified Prof C3D
Re: Point3d == Null
« Reply #5 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 :-)
The conclusion is justified that the initialization of the development of critical subsystem optimizes the probability of success to the development of the technical behavior over a given period.