Microsoft
98-361 · Question #383
You are C# developer who is developing a Windows application. You write the following code: Object o; Later in the code, you need to assign the value in the variable o to an object of Rectangle…
The correct answer is D. Rectangle r = o is Rectangle. See the full explanation below for the reasoning.
Question
You are C# developer who is developing a Windows application. You write the following code:
Object o; Later in the code, you need to assign the value in the variable o to an object of Rectangle type. You expect that at runtime the value in the variable o is compatible with the Rectangle class. However, you need to make sure that no exceptions are raised when the value is assigned. Which of the following code should you use?
Options
- ARectangle r = (Rectangle) o;
- BRectangle r = o;
- CRectangle r = o as Rectangle;
- DRectangle r = o is Rectangle;
How the community answered
(22 responses)- A5% (1)
- B5% (1)
- C9% (2)
- D82% (18)
Community Discussion
No community discussion yet for this question.