Nullable types

 

Introduction

Nullable types are instances of the System.Nullable struct. A nullable type can represent the normal range of values for its underlying value type, plus an additional null value.

 

 

Defining a nullable type

Only a value type can be made "nullable" (you cannot create nullable types on the basis of a referenced type).

 

To define a nullable type, select an attribute or parameter with a value type (a primitive type, a structure or an enumerated type) in the explorer and then associate the {CsNullableType} tagged value (without parameters) to it in the auxiliary window (as shown below).

 

The {CsNullableType} tagged value in the auxiliary window

 

Steps:                             

1.      To associate the {CsNullableType} tagged value to the element selected in the explorer, click on the "Associate a tagged value" icon in the auxiliary window and select it in the dropdown list.

2.      The {CsNullableType} tagged value then appears in the auxiliary window.  In the example above, it has an integer primitive type.

 

The "T?" syntax is the abbreviated format for System.Nullable<T>, where T is a value type.  The two formats are interchangeable.  However, only the abbreviated format syntax is used by Objecteering C# Developer during code generation, as it is more legible.