Answer 1)
The is operator checks whether an object is compatible with a given type, and the result of the evaluation is a Boolean: true or false. The is operator will never throw an exception.
An is expression evaluates to true if both of the following conditions are met: - expression is not null
- expression can be cast to type
The as operator is like a cast except that it yields null on conversion failure instead of raising an exception. More formally, an expression of the form: Employee e = obj as Employee;
is equivalent to:
Employee e = obj is Employee ? (Employee)obj : (Employee)null;
|