The C# as operator is equivalent to testing if an object is of a specific type with is and then performing a cast or returning null depending on the result. Performing an is check before calling as is completely redundant because an is check is performed twice.

Just use as on its own and then perform a null check on the result to determine if the cast was successful. Note in passing that it is no better to replace the 'as' with a cast, since that also does a type test internally.

In this example two type checks are performed for a against Rectangle.

Here is the same function performed more efficiently by omitting the extra type check.

  • MSDN: is
  • MSDN: as