mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2024-12-28 01:32:14 +03:00
Accessing nullable's value in C#
This commit is contained in:
parent
9a9b5a31e0
commit
2173dd419a
@ -144,6 +144,10 @@ namespace Learning
|
||||
int? nullable = null;
|
||||
Console.WriteLine("Nullable variable: " + nullable);
|
||||
|
||||
// In order to use nullable's value, you have to use Value property or to explicitly cast it
|
||||
string? nullableString = "not null";
|
||||
Console.WriteLine("Nullable value is: " + nullableString.Value + " or: " + (string) nullableString );
|
||||
|
||||
// ?? is syntactic sugar for specifying default value
|
||||
// in case variable is null
|
||||
int notNullable = nullable ?? 0;
|
||||
|
Loading…
Reference in New Issue
Block a user