From f827a14e78e9ef5f1df7d2ee095110e2bbb407f0 Mon Sep 17 00:00:00 2001 From: Mark J Price Date: Wed, 19 Jul 2023 08:18:31 +0100 Subject: [PATCH] Update Chapter02.dib --- notebooks/Chapter02.dib | 37 ------------------------------------- 1 file changed, 37 deletions(-) diff --git a/notebooks/Chapter02.dib b/notebooks/Chapter02.dib index ce53a0f..1e6d992 100644 --- a/notebooks/Chapter02.dib +++ b/notebooks/Chapter02.dib @@ -326,43 +326,6 @@ for (int i = 0; i < names.Length; i++) #!markdown -## Making a value type nullable - -#!csharp - -int thisCannotBeNull = 4; -// thisCannotBeNull = null; // compile error! - -int? thisCouldBeNull = null; -Console.WriteLine(thisCouldBeNull); -Console.WriteLine(thisCouldBeNull.GetValueOrDefault()); - -thisCouldBeNull = 7; -Console.WriteLine(thisCouldBeNull); -Console.WriteLine(thisCouldBeNull.GetValueOrDefault()); - -#!markdown - -## Checking for null - -#!csharp - -string authorName = null; - -// the following throws a NullReferenceException -// int x = authorName.Length; - -// instead of throwing an exception, null is assigned to y -int? y = authorName?.Length; - -Console.WriteLine($"y is null: {y is null}"); - -// result will be 3 if authorName?.Length is null -var result = authorName?.Length ?? 3; -Console.WriteLine(result); - -#!markdown - ## Formatting using numbered positional arguments #!csharp