Som Bhattacharyya Som Bhattacharyya - 1 year ago 81 Question

Option type in VB

Is there a

type that we can use in VB? I am working on a project in VB right now and am thinking of a way to get rid off all the
check on
and returning of
If i can have something of that sort i could statically ensure that a method returns an
instead of surprising callers by returning null .
That would make the code less error prone and would read so much better.

Answer Source

Short answer:


Long answer:

Support for proper option types, or algebraic data types in general, isn't coming to C# / VB.Net any time soon.

Support for non-nullable types, which aren't quite the same but would still allow compile-time null-checking, is planned for the upcoming C# 7. AFAIK it has not been confirmed yet that VB 15 will include the same feature though.

You can come up with a number of anti-NullReferenceException tricks on your own which minimise the chance of accidentally passing a null around, but it's simply not possible to make them 100% compile-time safe for the time being.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download