Personal notes on software development.
For Java technologies check my dedicated site

Pages

Nullable Types (C# Programming Guide)
Nullable types are instances of the System.Nullable struct. A nullable type can represent the correct range of values for its underlying value type, plus an additional null value.
Examples:

  • a Nullable int32, pronounced "Nullable of Int32," can be assigned any value from -2147483648 to 2147483647, or it can be assigned the null value.
  • a Nullable bool can be assigned the values truefalse, or null.
The ability to assign null to numeric and Boolean types is especially useful when you are dealing with databases and other data types that contain elements that may not be assigned a value. For example, a Boolean field in a database can store the values true or false, or it may be undefined.[1] 

The AddProduct method take in as parameters the values for the various product fields and add a new product. Since many of the Product table's columns can accept NULL values (CategoryID, SupplierID, and UnitPrice, to name a few), those input parameters for AddProduct that map to such columns use nullable types [2]:
[System.ComponentModel.DataObjectMethodAttribute]
    (System.ComponentModel.DataObjectMethodType.Insert, true)]
public bool AddProduct(string productName, int? supplierID,
    int? categoryID, string quantityPerUnit, decimal? unitPrice,
    short? unitsInStock, short? unitsOnOrder, short? reorderLevel,
    bool discontinued)
    {  
          (....)
    }

Related articles:
[1] - Nullable Types (C# Programming Guide)
[2] - Creating a Business Logic Layer

No comments:

Post a Comment