From 2173dd419a1daa06efee295e3fe2cdbc40224433 Mon Sep 17 00:00:00 2001 From: Max Yankov Date: Sat, 17 Aug 2013 15:57:52 +0200 Subject: [PATCH] Accessing nullable's value in C# --- csharp.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/csharp.html.markdown b/csharp.html.markdown index c254b5a9..c9df6db9 100644 --- a/csharp.html.markdown +++ b/csharp.html.markdown @@ -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;