Editorconfig Guide.e

Prefer pattern matching over as with null check

EditorConfig key: csharp-style-pattern-matching-over-as-with-null-check

Prefer pattern matching over as with null check

csharp-style-pattern-matching-over-as-with-null-check

This option controls whether pattern matching should be preferred over using the as operator followed by a null check.

Default value:

true

Possible values:

  • true
  • false

Examples

true
if (o is string s)
{
  return s;
}
false
string s = o as string;
if (s != null)
{
  return s;
}