You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/csharp/fundamentals/null-safety/resolve-warnings.md
+4-8Lines changed: 4 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ When you enable nullable reference types, the compiler issues warnings everywher
19
19
- Add or remove a `?` or `!` annotation.
20
20
- Add an attribute that describes the null contract.
21
21
- Initialize variables correctly.
22
-
-Configure the nullable context.
22
+
-Verify the project setting.
23
23
24
24
This article walks through each technique with a representative example. The goal isn't to silence warnings. It's to make the code's null-handling intent explicit so the compiler reaches the same conclusions you do.
25
25
@@ -113,19 +113,15 @@ You have several ways to address it. Pick the one that best matches your design
113
113
114
114
If a helper method initializes the member, annotate the helper with <xref:System.Diagnostics.CodeAnalysis.MemberNotNullAttribute> so the compiler can credit calls to it.
115
115
116
-
## Configure the nullable context
116
+
## Verify the project setting
117
117
118
118
New C# projects enable nullable reference types by default, so most code you write or read already has the feature turned on. You generally don't need to configure anything. If you're curious whether a project has it enabled, or you need to change the setting, look for the `<Nullable>` element in the `.csproj`:
The supported values are `enable` (the default for new projects), `disable`, `warnings`, and `annotations`. If the element is missing, the project uses whatever default the SDK and target framework set.
122
+
The common supported values are `enable` (the default for new projects)and `disable`. If the element is missing, the project uses whatever default the SDK and target framework set.
123
123
124
-
To change the setting for part of a file without affecting the rest of the project, use a [preprocessor directive](../../language-reference/preprocessor-directives.md) (a line starting with `#` that gives instructions to the compiler instead of producing executable code):
The `warnings` and `annotations` values turn on only part of the feature, and they're primarily useful in advanced scenarios such as migrating a large existing codebase one piece at a time. For those trade-offs, see [Nullable migration strategies](../../advanced-topics/update-applications/nullable-migration-strategies.md). For everyday work, `enable` and `disable` are the two values you need.
124
+
If you need to enable nullable for only part of a file with `#nullable` directives, or use the partial `warnings` and `annotations` modes when migrating an existing codebase, see [Nullable migration strategies](../../advanced-topics/update-applications/nullable-migration-strategies.md).
Copy file name to clipboardExpand all lines: docs/csharp/fundamentals/tutorials/nullable-reference-types.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,7 +46,7 @@ dotnet new console -n NullableIntroduction
46
46
cd NullableIntroduction
47
47
```
48
48
49
-
Open `NullableIntroduction.csproj` and confirm the `<Nullable>enable</Nullable>`element is set in the `PropertyGroup`. Templates from .NET 6 onward include it by default. If it's missing, add it manually:
49
+
Open `NullableIntroduction.csproj`. New console projects from .NET 6 onward set `<Nullable>enable</Nullable>` in the `PropertyGroup`; if it's missing, add it manually:
0 commit comments