Skip to content

no-empty-delegate-parens

C#stylefix: unsafedefault: offcsharp/stylecop

Reports an anonymous method with an empty parameter list: delegate() { } is delegate { }. Parentheses with a comment in them are not reported. The fix is unsafe: without a parameter list the method also converts to delegate types that have parameters, which can change which overload is chosen.

delegate { } is the shorter spelling of the same body, and the empty parentheses add nothing to read. They are not always the same to the compiler: the form without a list also converts to delegate types that have parameters, which can change which overload is chosen, and that is why the fix is unsafe.

Reported
...
[A, // why
...
int x;
Action a = delegate() { };
}
csharp:
lint:
rules:
no-empty-delegate-parens: warn # off (default), warn, error

Enabled by the presets: csharp/stylecop.

Suppress one line with sudsy-disable-next-line no-empty-delegate-parens in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
StyleCop SA1410 full