Home / Software / Tips and Tricks / what is the use of as operator in C Sharp?

what is the use of as operator in C Sharp?

Updated:  11/04/2013 08:11 AM
Author:  Shiju Mathews

Status:    Resolved.

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.

Note that the as operator performs only reference conversions, nullable conversions, and boxing conversions. The as operator can't perform other conversions, such as user-defined conversions, which should instead be performed by using cast expressions.

equivalent to the following expression except that the expression variable is evaluated only one time.