Question
I tested all the examples you provided (NET5, newest VS), and didn't get any compilation warnings you described.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: 0471f98c-f5cd-00d2-a705-396682f73bcb
- Version Independent ID: a24b862d-c462-a040-8470-9771c74c4e6f
- Content: ! (null-forgiving) operator - C# reference
- Content Source: docs/csharp/language-reference/operators/null-forgiving.md
- Product: dotnet-csharp
- Technology: csharp-language-reference
- GitHub Login: @BillWagner
- Microsoft Alias: wiwagn
@mcurko Can you check you have enabled nullable reference types? You need to do that both in the file containing Person class (the code in article already has #nullable enable), and also at the top of the test file and the file containing your main method.
Alternatively, you can do that in csproj or Directory.Build.props like the following:
<PropertyGroup>
<Nullable>enable</Nullable>
</PropertyGroup>
I think the point of confusion here is that the article isn't super clear about that. Please confirm.
I also encourage you to read Tutorial: Express your design intent more clearly with nullable and non-nullable reference types if you haven't.
This issue has been automatically closed due to no response from the original author. Please feel free to reopen it if you have more information that can help us investigate the issue further.