as

The as keyword defines a type conversion.

Purpose

This keyword is used to convert the type of an expression to another type.

Syntax

expression as type ;

Description

The as statement attempts to convert the type of the expression into the requested type, without raising a ClassCastException instance. If the conversion is possible, the as statement returns an expression with the correct type. It returns null if the conversion failed.

Example

Device e = server.getDevice();
Multiplex m = e as Multiplex;