JetBrains Rider
 
2024.3
Get JetBrains Rider

Code inspection: Variable can be declared as non-nullable

Last modified: 25 September 2024

If nullable reference types (NRT) are enabled, this inspection reports redundant nullable reference types' annotations (?) on variables whose value is determined to never be null based on the control flow analysis.

In the example below, the value of the myClass variable will never be null because it is assigned with a new instance of MyClass.

JetBrains Rider suggests removing the ? annotation on the type of the variable to improve readability and to avoid unnecessary null checks for usages of the variable.

For more information about NRT and how JetBrains Rider supports them, watch this webinar recording: