Remove ByVal (IDE0081)

Property Value
Rule ID IDE0081
Title Remove ByVal
Category Style
Subcategory Unnecessary code rules (expression-level preferences)
Applicable languages Visual Basic

Overview

This rule flags an unnecessary ByVal keyword in a parameter declaration in Visual Basic. Parameters in Visual Basic are ByVal by default, hence you do not need to explicitly specify it in method signatures. It tends to produce noisy code and often leads to the non-default ByRef keyword being overlooked.

Options

This rule has no associated code-style options.

Example

' Code with violations
Sub M(ByVal p1 As Integer, ByRef p2 As Integer)
End Sub

' Fixed code
Sub M(p1 As Integer, ByRef p2 As Integer)
End Sub

Suppress a warning

If you want to suppress only a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.

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

To disable the rule for a file, folder, or project, set its severity to none in the configuration file.

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

To disable all of the code-style rules, set the severity for the category Style to none in the configuration file.

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

For more information, see How to suppress code analysis warnings.

See also