Today I learned that you can use pattern matching in C# to check for a type and cast in the same expression docs

Microsoft has a lint rule for it.

if (x is Fruit)  // Noncompliant
{
  var f = (Fruit)x; // or x as Fruit
  // ...
}
if (x is Fruit fruit)
{
  // ...
}