Do you avoid using magic string when referencing property/variable names
  v1.0 Posted at 29/01/2020 4:35 PM by Liam Elliott
​Hard coded strings when referencing property and variable names can be problematic as your codebase evolves, and can make your code brittle.

​​(if customer.Address.ZipCode == null) throw new ArgumentNullException("ZipCode");

Figure: ​​​Bad Example - Hardcoding a reference to a property

​​(if customer.Address.ZipCode == null) throw new ArgumentNullException(nameof(customer.Address.ZipCode));

​​Figure: Good Example - Using nameof() operator to avoid hardcoded strings

Related rules

    Do you feel this rule needs an update?

    If you want to be notified when this rule is updated, please enter your email address: