What does the as operator return in C# when the conversion fails?
Correct answer A. null
Explanation
obj as T attempts a reference, nullable or boxing conversion and returns null if obj is not compatible with T. A cast written as (T)obj throws InvalidCastException instead. Because failure yields null, as can only be used with reference types or nullable value types, so x as int does not compile while x as int? does. Modern code often prefers obj is T t.
Answer checked How we write and check questions
Discussion