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.
'not null' pattern
publicstaticvoidTest(object? obj)
{
if(obj isnotnull)
Console.WriteLine("not null");
}
'{}' pattern
publicstaticvoidTest(object? obj)
{
if(obj is{})
Console.WriteLine("not null");
}
By default, JetBrains Rider highlights object pattern syntax { } in null-checking expressions and suggests replace them with the 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: