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
In questa pagina del sito puoi guardare il video online Nullable Value Types | C# della durata di ore minuti seconda in buona qualità , che l'utente ha caricato SharpDev 19 marzo 2022, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 126 volte e gli è piaciuto 6 spettatori. Buona visione!