Which of the following code should you use?

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?
A. Rectangle r = (Rectangle) o;
B. Rectangle r = o;
C. Rectangle r = o as Rectangle;
D. Rectangle r = o is Rectangle;

microsoft-exams

One thought on “Which of the following code should you use?

Leave a Reply

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


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