nerdexam
Microsoft

98-361 · Question #379

98-361 Question #379: Real Exam Question with Answer & Explanation

The correct answer is C. Polygon p = o as Polygon;. See the full explanation below for the reasoning.

Question

You are writing code for a new method named Process: void Draw(object o) { } The code receives a parameter of type object. You need to cast this object into the type Polygon. At times, the value of o that is passed to the method might not be a valid Polygon value. You need to make sure that the code does not generate any System. InvalidCastException errors while doing the conversions. Which of the following lines of code should you use inside the Draw method to accomplish this goal?

Options

  • APolygon p = (Polygon) o;
  • BPolygon p = o is Polygon;
  • CPolygon p = o as Polygon;
  • DPolygon p = (o != null) ? o as Polygon : (Polygon) o;

Community Discussion

No community discussion yet for this question.

Full 98-361 Practice