From ba7bf96b88ee3aa8db45652093112bff44f2027c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 3 Jul 2025 16:05:01 +0000 Subject: [PATCH 1/2] Initial plan From d02c3d5691be1f387abbbcf2ba30cb4934b494f9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 3 Jul 2025 16:09:08 +0000 Subject: [PATCH 2/2] Fix overstatement about nullable reference types protection Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --- docs/csharp/tutorials/nullable-reference-types.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/csharp/tutorials/nullable-reference-types.md b/docs/csharp/tutorials/nullable-reference-types.md index 04d01857d0102..8e84991d7cb64 100644 --- a/docs/csharp/tutorials/nullable-reference-types.md +++ b/docs/csharp/tutorials/nullable-reference-types.md @@ -124,7 +124,7 @@ namespace NullableIntroduction } ``` -As before, you must initialize the list object to a non-null value or the compiler issues a warning. There are no null checks in the second overload of `AddQuestion` because they aren't needed: You've declared that variable to be non-nullable. Its value can't be `null`. +As before, you must initialize the list object to a non-null value or the compiler issues a warning. There are no null checks in the second overload of `AddQuestion` because the compiler helps enforce the non-nullable contract: You've declared that variable to be non-nullable. While the compiler warns about potential null assignments, runtime null values are still possible. For public APIs, consider adding argument validation even for non-nullable reference types, since client code might not have nullable reference types enabled or could intentionally pass null. Switch to *Program.cs* in your editor and replace the contents of `Main` with the following lines of code: @@ -203,7 +203,7 @@ Finally, add the following loop at the bottom of the `Main` method: :::code language="csharp" source="./snippets/NullableIntroduction/Program.cs" id="WriteAnswers"::: -You don't need any `null` checks in this code because you've designed the underlying interfaces so that they all return non-nullable reference types. +You don't need any `null` checks in this code because you've designed the underlying interfaces so that they all return non-nullable reference types. The compiler's static analysis helps ensure these design contracts are followed. ## Get the code