C# has the as keyword, it is mainly used to cast object of one type to another, and if it fails it should return a null rather than crashing the program or throwing exception.

From MSDN documentation it states:
You can use the as operator to perform certain types of conversions between compatible reference types or nullable types. The as operator is like a cast operation. However, if the conversion isn’t possible, as returns null instead of raising an exception.

Differences between as and cast ( ) and when to use it:

  • Using “as“, I think the object is of the type, but if it isn’t give me a null, don’t crash the application.
  • Using cast, I know the object is of this type, and if it isn’t then crash the application.
  • Using is and cast is more costly than just using as