Skip to content

Commit 6982979

Browse files
authored
Update CA1806 with Pure methods (#49544)
1 parent e64f857 commit 6982979

File tree

1 file changed

+5
-4
lines changed
  • docs/fundamentals/code-analysis/quality-rules

1 file changed

+5
-4
lines changed

docs/fundamentals/code-analysis/quality-rules/ca1806.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "CA1806: Do not ignore method results (code analysis)"
33
description: "Learn about code analysis rule CA1806: Do not ignore method results"
4-
ms.date: 06/08/2022
4+
ms.date: 10/30/2025
55
f1_keywords:
66
- CA1806
77
- DoNotIgnoreMethodResults
@@ -32,6 +32,7 @@ There are several possible reasons for this warning:
3232
- A method that creates and returns a new string is called and the new string is never used.
3333
- A COM or P/Invoke method returns a `HRESULT` or error code that's never used.
3434
- A language-integrated query (LINQ) method returns a result that's never used.
35+
- A `[Pure]` method is called and the return value is never used.
3536

3637
## Rule description
3738

@@ -41,7 +42,7 @@ Strings are immutable and methods such as <xref:System.String.ToUpper%2A?display
4142

4243
Ignoring `HRESULT` or an error code can lead to low-resource conditions or unexpected behavior in error conditions.
4344

44-
LINQ methods are known to not have side effects, and the result should not be ignored.
45+
LINQ methods and methods annotated with <xref:System.Diagnostics.Contracts.PureAttribute> are known to not have side effects, and the result should not be ignored.
4546

4647
## How to fix violations
4748

@@ -57,7 +58,7 @@ If method A calls method B but does not use the `HRESULT` or error code that the
5758

5859
-or-
5960

60-
If a LINQ method A calls method B but does not use the result, use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method.
61+
If method A calls a LINQ or pure method B but does not use the result, use the result in a conditional statement, assign the result to a variable, or pass it as an argument to another method.
6162

6263
## When to suppress warnings
6364

@@ -122,7 +123,7 @@ The following example fixes the violation by assigning the result of <xref:Syste
122123
The following example shows a method that doesn't use an object that it creates.
123124

124125
> [!NOTE]
125-
> This violation cannot be reproduced in Visual Basic.
126+
> This violation can't be reproduced in Visual Basic.
126127
127128
:::code language="csharp" source="snippets/csharp/all-rules/ca1806.cs" id="snippet3":::
128129

0 commit comments

Comments
 (0)