使用隐式类型 lambda (IDE0350)

资产 价值
规则 ID IDE0350
标题 使用隐式类型 Lambda 表达式
类别 Style
子类别 语言规则(表达式级首选项)
适用的语言 C#
Options csharp_style_prefer_implicitly_typed_lambda_expression

概述

此规则标志将显式类型 化的 lambda 表达式 转换为隐式类型 lambda 表达式的位置。

选项

选项指定希望规则强制实施的行为。 有关配置选项的信息,请参阅 选项格式

csharp_style_prefer_implicitly_typed_lambda_expression

资产 价值 Description
选项名称 csharp_style_prefer_implicitly_typed_lambda_expression
选项值 true 首选使用隐式类型 lambda
false 禁用规则
默认选项值 true

Example

// Code with violations.
Action<int> a = (int x) => { };
Delegate b = (Action<int>)( (int x) => { } );
// Fixed code.
Action<int> a = x => { };
Delegate b = (Action<int>)( x => { } );

禁止显示警告

如果只想取消单个冲突,请将预处理器指令添加到源文件以禁用,然后重新启用规则。

#pragma warning disable IDE0350
// The code that's violating the rule is on this line.
#pragma warning restore IDE0350

若要禁用文件、文件夹或项目的规则,请在none中将其严重性设置为

[*.{cs,vb}]
dotnet_diagnostic.IDE0350.severity = none

若要禁用所有代码样式规则,请将类别 Style 的严重性设置为 none中的

[*.{cs,vb}]
dotnet_analyzer_diagnostic.category-Style.severity = none

有关详细信息,请参阅 如何禁止显示代码分析警告