|
|
|
|
Nullable Types
|
| |
|
| |
In programming, nullable type is a feature of some programming languages which allows a data type to be set to NULL instead of their common range of possible values.
In contrast, object references or pointers can be set to NULL by default in most common languages, meaning that the pointer or reference points to nowhere, that no object is assigned (the variable contains nothing). For value or data types like integers and booleans however, such behavior is mostly not possible.

Discussion
Ask a question about 'Nullable Types'
Start a new discussion about 'Nullable Types'
Answer questions from other users
|
Encyclopedia
In programming, nullable type is a feature of some programming languages which allows a data type to be set to NULL instead of their common range of possible values.
In contrast, object references or pointers can be set to NULL by default in most common languages, meaning that the pointer or reference points to nowhere, that no object is assigned (the variable contains nothing). For value or data types like integers and booleans however, such behavior is mostly not possible. Nullable Type support allows for the programmer to make also these value types NULL. This can be very useful when working with databases. A field in a Relational database like SQL may have an entry that is NULL (or empty) instead of containing a value. A language with Nullable Type support can then return a NULL value and correctly represent the behavior of the database.
Example An integer variable may contain a positive or negative natural number ( ..., -2, -1, 0, 1, 2, ...). The value 0 (zero) however is not the correct representation for this variable to contain nothing (it contains the value 0 and only the conception in the given context might suggest that 0 represents "nothing" instead of the actual representation: "nothing" of "something"). In many circumstances it is required to represent also the fact, that a variable has not been given any value at all. This can be achieved by a Nullable Type. In programming languages like C# 2.0 a Nullable integer for example can be declared by a question mark (int? x).
A boolean variable makes the effect even more clear. Their values can be either "true" or "false", while a nullable boolean may also contain a representation for "undecided". However, the interpretation of logical operation containing boolean nullable variables is up to the language that is being used.
Languages with Nullable Type support
|
| |
|
|