You can follow the playlist here: • C# Using Directives
A nullable value type T? represents all values of its underlying value type T and an additional null value.
E.g. for a bool?, true, false, null can be assigned to the variable.
E.g. Scenario you have to save and load an apartment number which is an integer value in a table whose column allows null value.
If the person doesn’t stay in an apartment, default integer value of 0 cannot be allowed to be saved.
Any value type is an instance of generic System.Nullable(T) structure.
Nullable(T) or T? forms are interchangeable.
Properties:
Nullable(T).HasValue - Indicates if instance of nullable type has value
Nullable(T).Value - gets the value of an underlying type if HasValue is true.
Remarks: If HasValue is false, Value property throws an InvalidOperationException.
Methods:
Nullable(T).GetValueOrDefault() - Retrieves the default value of the underlying type if no value has been set.
Nullable(T).GetValueOfDefault(T) - Returns the specified default value if no value has been set.
Nullable types and Is Operator:
DO NOT use the is operator to determine whether an instance is of nullable value type
Is operator cannot distinguish between types of a nullable value type instance and its underlying type instance
Key points to remember:
Nullable(T) or T? forms are interchangeable.
Accessing the Value property can throw InvalidOperationException
Use HasValue property before accessing the Value property.
Is operator cannot be used to distinguish between types of a nullable value type instance and its underlying type instance
Auf dieser Seite können Sie das Online-Video Nullable Value Types | C# mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer SharpDev 19 März 2022 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 126 Mal angesehen und es wurde von 6 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!