Review Questions


  1. How many dimensions does the array warpedWorld have if accessing one of its elements requires a line of code like the following:

  2. How many nested for loops would be required to access all elements in the warpedWorld array?


You are considering writing a chess-playing program. How many dimensions would the array representing the chessboard need to have?

  1. Declare a rectangular three-dimensional array called observations with base type uint. Assign to it a reference to a new array object with the following numbers of elements in each dimension 5, 10, 20.

  2. Write a statement that assigns the value 100 to the observations element with indexes 3, 2, 10.

  3. What happens if you attempt to access the element with indexes 1, 12, 14?

  4. d. Write nested for loops to access and print onscreen the value of each element in the observations array.

  5. Use the foreach loop to perform the same operation as in question d.

  1. Declare a jagged two-dimensional array called numbers of base type int, in which the first dimension contains 7 elements.

  2. Declare the third element of the first dimension to contain a one-dimensional array of length 20.

  3. Assign the value 100 to the fourth element in the array contained in the third element of the first dimension.


Suppose an array called numbers is declared as follows:

 int [] numbers = {2, 4, 6, 8, 10, 12, 6} ; 

Which values do the following method calls return?

  1. System.Array.IndexOf(numbers, 6)

  2. System.Array.IndexOf(numbers, 7)

  3. System.Array.IndexOf(numbers, 2, 3)

  4. System.Array.LastIndexOf(numbers, 6)

  5. System.Array.Reverse(numbers) followed by System.Array.IndexOf(numbers, 12)


Suppose that your program is searching an array containing one million data items by using the binary search algorithm. How many data items does it discard (and need not to look at again) from the search during the first search loop?


Your program needs to search for a value in an array of length 2048. What is the maximum number of loops required to find the value by using a

  1. Sequential search

  2. Binary search


C# Primer Plus
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2000
Pages: 286
Authors: Stephen Prata

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: