Skip to content

Commit af845c8

Browse files
CopilotBillWagner
andauthored
Fix overstatement about nullable reference types runtime protection (#47090)
* Initial plan * Fix overstatement about nullable reference types protection Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
1 parent c7ae7d1 commit af845c8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docs/csharp/tutorials/nullable-reference-types.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ namespace NullableIntroduction
124124
}
125125
```
126126

127-
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`.
127+
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.
128128

129129
Switch to *Program.cs* in your editor and replace the contents of `Main` with the following lines of code:
130130

@@ -203,7 +203,7 @@ Finally, add the following loop at the bottom of the `Main` method:
203203

204204
:::code language="csharp" source="./snippets/NullableIntroduction/Program.cs" id="WriteAnswers":::
205205

206-
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.
206+
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.
207207

208208
## Get the code
209209

0 commit comments

Comments
 (0)