Max Params

ID

csharp.max_params

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

medium

Resource

Complexity

Language

CSharp

Tags

complexity

Description

Reports a method or constructor whose parameter count exceeds a configurable threshold (default 7). A long parameter list is hard to call correctly and hard to read at the call site, where positional arguments of the same type are easy to transpose.

Rationale

When a method takes many parameters it usually means it is doing several things at once, or that several of those parameters travel together and belong in their own type. Long lists also defeat readability: Create(true, false, 3, null, "x", 0, 7, false) tells the reader almost nothing. Grouping related parameters into a dedicated options object or record both documents intent and shrinks the call site.

// FLAW — 8 parameters
void Process(int a, int b, int c, int d, int e, int f, int g, int h) { }

// OK — related parameters grouped into one object
void Process(ProcessOptions options) { }

Remediation

Introduce a parameter object (a class, record or struct) that groups the related arguments, or split the method into smaller methods that each take fewer parameters. The threshold is configurable through the maxParams property.