Which code segment should you insert at line 07?

You are developing an application by using C#. The application includes the following code segment. (Line numbers are included for reference only.)

The DoWork() method must not throw any exceptions when converting the obj object to the IDataContainer interface or when accessing the Data property.
You need to meet the requirements. Which code segment should you insert at line 07?
A. var dataContainer = (IDataContainer)obj;
B. dynamic dataContainer = obj;
C. var dataContainer = obj is IDataContainer;
D. var dataContainer = obj as IDataContainer;

microsoft-exams

2 thoughts on “Which code segment should you insert at line 07?

  1. “As – The as operator is like a cast operation. However, if the conversion isn’t possible, as returns null instead of raising an exception.”
    OK

    Req of task: “must not throw any exceptions when converting the obj object to the IDataContainer interface or when accessing the Data property.”

    var dataContainer = obj as IDataContainer will not trow ex and dataContainer = null.

    And what we will have in line 10 when will accessing Data prop of null object???

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.