Nullable Types

is there a way to mimic nullable types like in c#. let’s say i have a hittest and save to result into a pad, but in case there isn’t any hit result, the pad has still content and isn’t null. but it would be helpful to know if there isn’t anything hence the pad is null.

any hints or best practise regarding this ?

You can use Nullable in VL. Nullable.HasValue() tells you if there’s a value or if it’s Null.

Cool thing is, that Nullable is recognized by the HDE, so that you can for example connect an iobox directly to a Nullable Input without having to use some boilerplate Nodes like create Nullable, etc.
Is that what you need?

i’m struggeling to create a pad with a nullable type, can you make a screenshot ?

How about Optionals as well?

image

If you need to specifically mimic behaviour, this is a well-done concept that is widely used internally.
If for some reason you need Nullable, it is a little harder to use in Gamma.

1 Like

image

hm, i didin’t remember that it was necessary to create each nullable like in the screenshot.

it aligns also with imported types that make use of Nullable Parameters for example.


Nullable and Optional seemed quite similar to me and i didn’t look the differences up, yet.

… While writing this and comparing them a bit i find Optional a bit more forgiving.

Nullable_Optional.vl (23.3 KB)

1 Like

thanks guys, that was pointing in the right direction. i will implement this…probably go for optional

Nullable only allows value types. Optional allows any type. So yes, optional would be the preferred way. Nullable we support as well because it’s often used in libraries.

1 Like

image
yes, that works like a charm