QUIZ

CHAPTER 6

Your Name:


6.1 If the following is written in a program, what will happen?

   1	double[] a = new double[10];
   2	for (int i=1; i<=10; i++)
   3		a[i] = i;
   4	Console.WriteLine("Completed");

(a) Completed will be printed
(b) IndexOutOfRangeException will be raised
(c) Compilation error at line 3 because a is a double array
(d) Compilation error because a[0] does not have a value

6.2 An exception is implemented in C# as

(a) an object
(b) a string
(c) an array
(d) an integer variable

6.3 If all tests get past the Debug.Assert method, it is most likely that:

(a) The program is perfectly correct
(b) The tests in Debug.Assert used or’s instead of and’s
(c) The /define:DEBUG option was not set
(d) The /define:DEBUG option was set


6.4 A programmer puts Debug.WriteLine statements in a program, but there is no output. The likely cause is:

(a) The /define:DEBUG option was not set
(b) No listener was provided for the output
(c) Debug.AutoFlush was not called
(d) Any of the above

6.5 If the following is written in a program, what will happen?

   1	int i = 3; int j = 0;
   2	try {
   3		Console.WriteLine("Answer = "+(i/j));
   4	} catch(DivideByZeroException) {
   5		Console.Writeln("Zero");
   6	} catch(Exception) {
   7		Console.WriteLine("Exception");
   8	}

(a) Answer = 0 will be printed
(b) Exception will be printed
(c) Zero will be printed
(d) Nothing will be printed