JetBrains Rider
 
2024.3
Get JetBrains Rider

Code inspection: Arrange null checking pattern

Last modified: 11 February 2024

When checking an expression for null with the type-testing 'is' operator, you can choose between two null-checking patterns:

  • Use the 'not null' pattern that makes the expression more readable.

  • Use the object pattern syntax `{ }` that makes the expression more flexible, allowing you to declare a local variable after it.

By default, JetBrains Rider highlights object pattern syntax { } in null-checking expressions and suggests replace them with the not null pattern:

JetBrains Rider syntax style inspection: Use 'not null' pattern

If you prefer to use the { } pattern, you can change the corresponding preferences and JetBrains Rider will help you replace not null patterns accordingly:

JetBrains Rider syntax style inspection: Use '{ }' pattern

For more information, refer to Code Syntax Style: Null checking pattern.