TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
C# Coding Standard
Search

Rule:  7@608Checked automatically with code checker

Synopsis:Use pattern matching instead of the "as" keyword
Language:C#
Severity Level:5
Category:Object oriented


Description:

Since C# 7 it is possible to perform safe casting by only using the "is" operator. In previous days you had to do something like this:

string text = input as string;
if(text != null)
{
  ...
}

It is more convenient to write this in the following way:

if(input is string text)
{
  ...
}

The pattern will not match if input is null and non-nullable types like int are supported as well.



Literature References:
Daniel Crabtree