Practice Questions

Question 1You have created the following code segment:
try
{
   //Write code to allocate some resources
}
finally
{
   //Write code to Dispose all allocated resources
}

Which of the following will result from compiling this code, assuming that all other code for your form works properly?

  • A. The code will generate an error because it lacks a catch block.

  • B. The code will generate an error because it lacks a throw statement.

  • C. The code will generate an error because the finally block is placed immediately after the try block.

  • D. The code will compile without an error.

A1: Answer D is correct. The code will compile properly because a try block should be followed by either a catch block or a finally block. The code here includes both ...

Get Developing and Implementing Windows®-Based Applications with Visual C#™ .NET and Visual Studio® .NET Exam Cram™ 2 (Exam 70-316) now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.