The is
operator is used to check whether the run-time type of an object is compatible with a given type. In an operation of the form e
is
T
, e
must be an expression of a reference-type and T
must be a reference-type. If this is not the case, a compile-time error occurs.
The operation e
is
T
returns true
if e
is not null
and if an implicit reference conversion (§6.1.4) from the run-time type of the instance referenced by e
to the type given by T
exists. In other words, e
is
T
checks that e
is not null
and that a cast-expression (§7.6.8) of the form (T)(e)
will complete without throwing an exception.
If e
is
T
is known at compile-time to always be true
or always be false
, a compile-time error occurs. The operation is known to always be true
if an implicit reference conversion exists from the compile-time type of e
to T
. The operation is known to always be false
if no implicit or explicit reference conversion exists from the compile-time type of e
to T
.