|
| 1 | +--- |
| 2 | +title: "IDE0350: Use implicitly typed lambda" |
| 3 | +description: "Learn about code analysis rule IDE0350: Use implicitly typed lambda" |
| 4 | +ms.date: 03/25/2025 |
| 5 | +f1_keywords: |
| 6 | +- IDE0350 |
| 7 | +helpviewer_keywords: |
| 8 | +- IDE0350 |
| 9 | +dev_langs: |
| 10 | +- CSharp |
| 11 | +--- |
| 12 | +# Use implicitly typed lambda (IDE0350) |
| 13 | + |
| 14 | +| Property | Value | |
| 15 | +|--------------------------|----------------------------------------------------------| |
| 16 | +| **Rule ID** | IDE0350 | |
| 17 | +| **Title** | Use implicitly typed lambda | |
| 18 | +| **Category** | Style | |
| 19 | +| **Subcategory** | Language rules (expression-level preferences) | |
| 20 | +| **Applicable languages** | C# 14+ | |
| 21 | +| **Options** | `csharp_style_prefer_implicitly_typed_lambda_expression` | |
| 22 | + |
| 23 | +## Overview |
| 24 | + |
| 25 | +This rule flags places where an explicitly typed [lambda expression](../../../csharp/language-reference/operators/lambda-expressions.md) can be converted to an implicitly typed lambda expression. |
| 26 | + |
| 27 | +## Options |
| 28 | + |
| 29 | +Options specify the behavior that you want the rule to enforce. For information about configuring options, see [Option format](language-rules.md#option-format). |
| 30 | + |
| 31 | +### csharp_style_prefer_implicitly_typed_lambda_expression |
| 32 | + |
| 33 | +| Property | Value | Description | |
| 34 | +|--------------------------|--------------------------------------------------------|------------------------------------------| |
| 35 | +| **Option name** | csharp_style_prefer_implicitly_typed_lambda_expression | | |
| 36 | +| **Option values** | `true` | Prefer to use an implicitly typed lambda | |
| 37 | +| | `false` | Disables the rule | |
| 38 | +| **Default option value** | `true` | | |
| 39 | + |
| 40 | +## Example |
| 41 | + |
| 42 | +```csharp |
| 43 | +// Code with violations. |
| 44 | +Action<int> a = (int x) => { }; |
| 45 | +Delegate b = (Action<int>)( (int x) => { } ); |
| 46 | +``` |
| 47 | + |
| 48 | +```csharp |
| 49 | +// Fixed code. |
| 50 | +Action<int> a = x => { }; |
| 51 | +Delegate b = (Action<int>)( x => { } ); |
| 52 | +``` |
| 53 | + |
| 54 | +## Suppress a warning |
| 55 | + |
| 56 | +If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule. |
| 57 | + |
| 58 | +```csharp |
| 59 | +#pragma warning disable IDE0350 |
| 60 | +// The code that's violating the rule is on this line. |
| 61 | +#pragma warning restore IDE0350 |
| 62 | +``` |
| 63 | + |
| 64 | +To disable the rule for a file, folder, or project, set its severity to `none` in the [configuration file](../configuration-files.md). |
| 65 | + |
| 66 | +```ini |
| 67 | +[*.{cs,vb}] |
| 68 | +dotnet_diagnostic.IDE0350.severity = none |
| 69 | +``` |
| 70 | + |
| 71 | +To disable all of the code-style rules, set the severity for the category `Style` to `none` in the [configuration file](../configuration-files.md). |
| 72 | + |
| 73 | +```ini |
| 74 | +[*.{cs,vb}] |
| 75 | +dotnet_analyzer_diagnostic.category-Style.severity = none |
| 76 | +``` |
| 77 | + |
| 78 | +For more information, see [How to suppress code analysis warnings](../suppress-warnings.md). |
0 commit comments