nerdexam
Microsoft

98-361 · Question #379

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…

Sign in or unlock 98-361 to reveal the answer and full explanation for question #379. The question stem and answer options stay visible for context.

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;

Unlock 98-361 to see the answer

You've previewed enough free 98-361 questions. Unlock 98-361 for full answers, explanations, the timed quiz mode, progress tracking, and the master PDF. Question stem and options stay visible so you can still see what's on the exam.

Full 98-361 Practice