ReSharper
 
Get ReSharper
Get your hands on the new features ahead of the release by joining the Early Access Program for ReSharper 2025.1! Learn more

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, ReSharper highlights object pattern syntax { } in null-checking expressions and suggests replace them with the not null pattern:

ReSharper syntax style inspection: Use 'not null' pattern

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

ReSharper syntax style inspection: Use '{ }' pattern

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