View Article
07
I ran accross this article about nullable types in VB 9.0. Basically, there is now integrated syntax to denote a nullable type. For example:
Dim age As Integer?
You will then see that the variable age now has the property .HasValue that can be checked to see if the value is null or not. This has great potential for the whole issue about databases storing nulls and co-ordinating it with our OOP programming.
 
Here's another snippet from the article:

The use of nullables goes even further by means of three-valued logic and null propagation when working with arithmetic operations on nullable value types. Take a look at the following fragment:

Dim a As Integer? = Nothing
Dim b As Integer? = 123
Dim c As Integer? = a + b

In here c will get the 'value' Nothing. Thus, whenever you apply arithmetic operations on one or more nullables of which one is null-valued (Nothing), the result will be the null value too.

Nullable types are especially useful when mapping database schemas to objects, as is done in LINQ to SQL for example. Tomorrow, we'll look at the Ternary Operator 'If' which makes working with these Nullable Types easier in some cases.

Posted in: VB.NET

Comments

There are currently no comments, be the first to post one.

Post Comment

Name (required)

Email (required)

Website

CAPTCHA image
Enter the code shown above in the box below