Backing Fields- Nullable type
Nullable Type
- Allow definition of a value OR null
a nullable type is a value type, such as integer, decimal or date, that allows definition of value or null.
- Specified with a "?" suffix on the type
- Distinguishes "not set" from the value type.
for example, if we declared the cost as a decimal value and that value was 0, does that mean that the cost was not yet set?
or that the cost was set and the actual cost is 0?
A nullable type helps us makes that distinction.
Nullable Type Best Practices
Do:
- use on simple types to distinguish "not set" and "default value".
- Use properties of the type such as HasValue and Value as needed.
Avoid:
- using them if they are not necessary
Comments
Post a Comment