Skip to content

Commit c21fd4a

Browse files
committed
resolve warnings, part 2
1 parent 2e5867f commit c21fd4a

4 files changed

Lines changed: 23 additions & 23 deletions

File tree

docs/csharp/advanced-topics/update-applications/nullable-migration-strategies.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ ai-usage: ai-assisted
1111
> [!TIP]
1212
> **Starting a new project?** New projects created from .NET 6 or later templates already have `<Nullable>enable</Nullable>` set. You don't need a migration strategy: skip to [Resolve nullable warnings](../../fundamentals/null-safety/common-tasks/resolve-warnings.md).
1313
>
14-
> **Maintaining an existing codebase?** Read [Nullable reference types](../../fundamentals/null-safety/common-tasks/nullable-reference-types.md) first to understand contexts, annotations, and null-state. This article assumes you're familiar with those concepts and ready to plan a rollout.
14+
> **Maintaining an existing codebase?** Read [Nullable reference types](../../fundamentals/null-safety/nullable-reference-types.md) first to understand contexts, annotations, and null-state. This article assumes you're familiar with those concepts and ready to plan a rollout.
1515
1616
When you turn on nullable reference types on a large project that started before nullable reference types were introduced, the compiler produces many warnings at once. Migration is about *sequencing* the work: choosing a default context, exposing warnings file by file or section by section, and converging on `<Nullable>enable</Nullable>` for the whole project. The right sequence depends on how active the codebase is and how much risk you can take in a single pass.
1717

@@ -100,7 +100,7 @@ You're now in the same state as new projects: nullable reference types are part
100100

101101
## Related content
102102

103-
- [Nullable reference types](../../fundamentals/null-safety/common-tasks/nullable-reference-types.md)
103+
- [Nullable reference types](../../fundamentals/null-safety/nullable-reference-types.md)
104104
- [Resolve nullable warnings](../../fundamentals/null-safety/common-tasks/resolve-warnings.md)
105105
- [Nullable static analysis attributes](../../language-reference/attributes/nullable-analysis.md)
106106
- [Working with nullable reference types in EF Core](/ef/core/miscellaneous/nullable-reference-types)

docs/csharp/fundamentals/null-safety/common-tasks/resolve-warnings.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ ai-usage: ai-assisted
99
# Resolve nullable warnings
1010

1111
> [!TIP]
12-
> **New to nullable reference types?** Read [Nullable reference types](nullable-reference-types.md) first to understand annotations and null-state analysis. This article assumes you're seeing warnings in a project where the feature is enabled.
12+
> **New to nullable reference types?** Read [Nullable reference types](../nullable-reference-types.md) first to understand annotations and null-state analysis. This article assumes you're seeing warnings in a project where the feature is enabled.
1313
>
14-
> **Looking for a specific compiler error code?** The [Resolve nullable warnings](../../language-reference/compiler-messages/nullable-warnings.md) reference article catalogs every CS86xx warning with the matching technique.
14+
> **Looking for a specific compiler error code?** The [Resolve nullable warnings](../../../language-reference/compiler-messages/nullable-warnings.md) reference article catalogs every CS86xx warning with the matching technique.
1515
1616
When you enable nullable reference types, the compiler issues warnings everywhere your code's behavior doesn't match its annotations. Most warnings fall into a small set of patterns. Once you recognize the pattern, the fix is usually one of five techniques:
1717

@@ -42,7 +42,7 @@ The fix is usually a *guard clause*. A *guard clause* is a check at the top of a
4242

4343
:::code language="csharp" source="snippets/resolve-warnings/Program.cs" id="DereferenceFixed":::
4444

45-
[Pattern matching](../../language-reference/operators/patterns.md) (expressions such as `is null` or `is { }` that test the shape of a value), `??`, and `??=` include null checks:
45+
[Pattern matching](../../../language-reference/operators/patterns.md) (expressions such as `is null` or `is { }` that test the shape of a value), `??`, and `??=` include null checks:
4646

4747
:::code language="csharp" source="snippets/resolve-warnings/Program.cs" id="NullOperatorsFix":::
4848

@@ -73,7 +73,7 @@ Sometimes the right fix isn't at the call site. A method's signature doesn't cap
7373

7474
:::code language="csharp" source="snippets/resolve-warnings/Program.cs" id="MissingAttribute":::
7575

76-
The body of `IsPresent` proves the argument isn't null when the method returns `true`, but the signature doesn't say so. Add a [nullable analysis attribute](../../language-reference/attributes/nullable-analysis.md) to make the contract part of the API:
76+
The body of `IsPresent` proves the argument isn't null when the method returns `true`, but the signature doesn't say so. Add a [nullable analysis attribute](../../../language-reference/attributes/nullable-analysis.md) to make the contract part of the API:
7777

7878
:::code language="csharp" source="snippets/resolve-warnings/Program.cs" id="WithAttribute":::
7979

@@ -84,21 +84,21 @@ Common attributes include:
8484
- <xref:System.Diagnostics.CodeAnalysis.MemberNotNullAttribute> — the listed members are *not-null* after the method returns.
8585
- <xref:System.Diagnostics.CodeAnalysis.DoesNotReturnAttribute> — the method never returns normally (for example, it always throws).
8686

87-
The full list is in [Nullable static analysis attributes](../../language-reference/attributes/nullable-analysis.md).
87+
The full list is in [Nullable static analysis attributes](../../../language-reference/attributes/nullable-analysis.md).
8888

8989
## Initialize non-nullable members
9090

91-
A constructor warning means a non-nullable field, property, or [auto-property](../../programming-guide/classes-and-structs/auto-implemented-properties.md) (a property that uses the compiler-generated backing field, such as `public string Name { get; set; }`) exits the constructor without being assigned a non-null value:
91+
A constructor warning means a non-nullable field, property, or [auto-property](../../../programming-guide/classes-and-structs/auto-implemented-properties.md) (a property that uses the compiler-generated backing field, such as `public string Name { get; set; }`) exits the constructor without being assigned a non-null value:
9292

9393
:::code language="csharp" source="snippets/resolve-warnings/Program.cs" id="UninitializedMember":::
9494

9595
You have several ways to address it. Pick the one that best matches your design intent.
9696

97-
**Require the value as a constructor argument.** Use a [primary constructor](../../whats-new/tutorials/primary-constructors.md) (parameters declared on the type itself, available throughout the body) or a regular constructor that initializes the property:
97+
**Require the value as a constructor argument.** Use a [primary constructor](../../../whats-new/tutorials/primary-constructors.md) (parameters declared on the type itself, available throughout the body) or a regular constructor that initializes the property:
9898

9999
:::code language="csharp" source="snippets/resolve-warnings/Program.cs" id="ConstructorInjected":::
100100

101-
**Make the property `required`.** The caller must initialize it through an [object initializer](../../programming-guide/classes-and-structs/object-and-collection-initializers.md) (the `{ Property = value }` syntax that follows `new`):
101+
**Make the property `required`.** The caller must initialize it through an [object initializer](../../../programming-guide/classes-and-structs/object-and-collection-initializers.md) (the `{ Property = value }` syntax that follows `new`):
102102

103103
:::code language="csharp" source="snippets/resolve-warnings/Program.cs" id="RequiredMember":::
104104

@@ -123,18 +123,18 @@ New C# projects enable nullable reference types by default, so most code you wri
123123

124124
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.
125125

126-
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).
126+
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).
127127

128128
## Where to go next
129129

130-
When a warning doesn't fit any of these patterns, the [Resolve nullable warnings](../../language-reference/compiler-messages/nullable-warnings.md) reference article lists the technique for every CS86xx warning the compiler emits.
130+
When a warning doesn't fit any of these patterns, the [Resolve nullable warnings](../../../language-reference/compiler-messages/nullable-warnings.md) reference article lists the technique for every CS86xx warning the compiler emits.
131131

132-
To plan a migration that progressively enables nullable reference types in an existing codebase, see [Nullable migration strategies](../../advanced-topics/update-applications/nullable-migration-strategies.md).
132+
To plan a migration that progressively enables nullable reference types in an existing codebase, see [Nullable migration strategies](../../../advanced-topics/update-applications/nullable-migration-strategies.md).
133133

134134
## Related content
135135

136136
- [Nullable reference types](nullable-reference-types.md)
137137
- [Null operators](null-operators.md)
138-
- [Nullable migration strategies](../../advanced-topics/update-applications/nullable-migration-strategies.md)
139-
- [Nullable static analysis attributes](../../language-reference/attributes/nullable-analysis.md)
140-
- [Resolve nullable warnings (compiler reference)](../../language-reference/compiler-messages/nullable-warnings.md)
138+
- [Nullable migration strategies](../../../advanced-topics/update-applications/nullable-migration-strategies.md)
139+
- [Nullable static analysis attributes](../../../language-reference/attributes/nullable-analysis.md)
140+
- [Resolve nullable warnings (compiler reference)](../../../language-reference/compiler-messages/nullable-warnings.md)

docs/csharp/fundamentals/strings/common-tasks/search.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ai-usage: ai-assisted
99
# Search strings in C\#
1010

1111
> [!TIP]
12-
> This article is part of the **Fundamentals** section for developers who already know at least one programming language and are learning C#. If you're new to programming, start with the [Get started](../../tour-of-csharp/tutorials/index.md) tutorials first.
12+
> This article is part of the **Fundamentals** section for developers who already know at least one programming language and are learning C#. If you're new to programming, start with the [Get started](../../../tour-of-csharp/tutorials/index.md) tutorials first.
1313
>
1414
> **Coming from another language?** C# `string` methods such as `Contains`, `StartsWith`, and `IndexOf` parallel methods in Java's `String` and JavaScript's `String.prototype`. The key difference is that some C# searches default to **ordinal, case-sensitive** comparison. Others default to the current culture's semantics. For user-facing searches, you might want to pass a <xref:System.StringComparison> value.
1515
@@ -18,7 +18,7 @@ The <xref:System.String> class includes methods that answer two everyday questio
1818
- *Does this string contain that text?* — use <xref:System.String.Contains*>, <xref:System.String.StartsWith*>, or <xref:System.String.EndsWith*>.
1919
- *Where does that text occur?* — use <xref:System.String.IndexOf*> or <xref:System.String.LastIndexOf*>.
2020

21-
For regular expressions, span-based search over `ReadOnlySpan<char>`, and performance considerations, see [String operations](../../language-reference/builtin-types/string-operations.md). For an in-depth treatment of culture-aware comparison, see [Best practices for comparing strings](../../../standard/base-types/best-practices-strings.md).
21+
For regular expressions, span-based search over `ReadOnlySpan<char>`, and performance considerations, see [String operations](../../../language-reference/builtin-types/string-operations.md). For an in-depth treatment of culture-aware comparison, see [Best practices for comparing strings](../../../../standard/base-types/best-practices-strings.md).
2222

2323
## Check whether a string contains text
2424

@@ -54,8 +54,8 @@ Ordinal comparison is the fastest option and the right default for anything that
5454

5555
## See also
5656

57-
- [String operations: pattern matching, performance, and span-based search](../../language-reference/builtin-types/string-operations.md)
58-
- [Best practices for comparing strings in .NET](../../../standard/base-types/best-practices-strings.md)
59-
- [Comparing strings](../../../standard/base-types/comparing.md)
57+
- [String operations: pattern matching, performance, and span-based search](../../../language-reference/builtin-types/string-operations.md)
58+
- [Best practices for comparing strings in .NET](../../../../standard/base-types/best-practices-strings.md)
59+
- [Comparing strings](../../../../standard/base-types/comparing.md)
6060
- <xref:System.String?displayProperty=nameWithType>
6161
- <xref:System.StringComparison?displayProperty=nameWithType>

docs/csharp/how-to/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ Strings are the fundamental data type used to display or manipulate text. These
4444
- [Compare strings](compare-strings.md).
4545
- [Modify the contents of a string](modify-string-contents.md).
4646
- [Determine if a string represents a number](../programming-guide/strings/how-to-determine-whether-a-string-represents-a-numeric-value.md).
47-
- [Use `String.Split` to separate strings](../fundamentals/common-tasks/strings/split.md).
47+
- [Use `String.Split` to separate strings](../fundamentals/strings/common-tasks/split.md).
4848
- [Combine multiple strings into one](concatenate-multiple-strings.md).
49-
- [Search for text in a string](../fundamentals/common-tasksstrings/search.md).
49+
- [Search for text in a string](../fundamentals/strings/common-tasks/search.md).
5050

5151
## Convert between types
5252

0 commit comments

Comments
 (0)