C#

C#

By DeepSource

Use `nameof` operator instead of explicitly spelling out the parameterCS-R1059
Anti-pattern
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.

Empty `default` label is redundantCS-R1022
Anti-pattern

default case in a switch is executed when none of the provided cases match. Since an empty default case does nothing, it is redundant and can be safely dropped/discarded.

Consider rewriting `Nullable<T>` as `T?`CS-R1047
Anti-pattern
Autofix

System.Nullable<T> indicates that the type T may be null. However, the said syntax can be shortened to T?. This is more concise, readable, and easy to comprehend, especially for programmers coming from languages such as TypeScript.

Use aliases when using built-in typesCS-R1000
Anti-pattern

Most of the built-in types in the language have aliases defined for them. Some such examples are:

[Type] [Alias] 1. System.String [String] -> string 2. System.Boolean [Boolean] -> bool 3. System.Byte [Byte] -> byte 4. System.Int32 [Int32] -> int

and so on. Therefore, it is suggested that you use these aliases when and where possible.

Do not overload the `==` operator to perform value equality checksCS-R1001
Anti-pattern

Operators such as == and != are expected to perform reference comparisons rather than compare values. If you intend to compare two different objects, consider implementing a relevant method in your class or look into interfaces such as IComparable<T> and IEquatable<T>.