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.
default
case in a switch
is executed when none of the provided case
s match. Since an empty default
case does nothing, it is redundant and can be safely dropped/discarded.
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.
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.
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>
.