C#

C#

Made by DeepSource

Use nameof operator instead of explicitly spelling out the parameter CS-R1059

Anti-pattern
Major
Autofix

ArgumentException is generally thrown when an unexpected argument is passed to a method. Explicitly spelling out the parameter whilst throwing such exceptions is not a good idea as parameter names are subject to change during code refactoring and may produce misleading information in the stracktrace. It is therefore recommended that you use the nameof operator to spell out such parameters instead.

Bad Practice

throw new ArgumentException("age");

Recommended

throw new ArgumentException(nameof(age));

Reference