Self-Review Exercises

  1. 8.1 Fill in the blank(s) in each of the following statements:

    1. Lists and tables of values can be stored in                .

    2. An array is a group of                 (called elements) containing values that all have the same                .

    3. The                 statement allows you to iterate through the elements in an array without using a counter.

    4. The number that refers to a particular array element is called the element’s                .

    5. An array that uses two indices is referred to as a(n)                 array.

    6. Use the foreach header                 to iterate through double array numbers.

    7. Command-line arguments are stored in                .

    8. Use the expression                 to receive the total number of arguments in a command line. Assume that command-line arguments are stored in args.

    9. Given the command MyApp test, the first command-line argument is                .

    10. A(n)                 in the parameter list of a method indicates that the method can receive a variable number of arguments.

    11. As of C# 6, you can declare                 auto-implemented properties, which are read-only properties.

  2. 8.2 Determine whether each of the following is true or false. If false, explain why.

    1. A single array can store values of many different types.

    2. An array index should normally be of type float.

    3. An individual array element that’s passed to a method and modified in that method will contain the modified value when the called method completes execution.

    4. Command-line arguments are separated by commas.

    5. Auto-implemented properties cannot be initialized in their declarations.

  3. 8.3 Perform the following tasks for an array called fractions:

    1. Declare constant ArraySize initialized to 10.

    2. Declare variable fractions which will reference an array with ArraySize elements of type double. Initialize the elements to 0.

    3. Name the element of the array with index 3.

    4. Assign the value 1.667 to the array element with index 9.

    5. Assign the value 3.333 to the array element with index 6.

    6. Sum all the elements of the array, using a for statement. Declare integer variable x as a control variable for the loop.

    7. Sum all the elements of the array, using a foreach statement. Declare double variable element as a control variable for the loop.

  4. 8.4 Perform the following tasks for an array called table:

    1. Declare the variable and initialize it with a rectangular integer array that has three rows and three columns. Assume that constant ARRAY_SIZE has been declared to be 3.

    2. How many elements does the array contain?

    3. Use a nested for statement to initialize each element of the array to the sum of its indices.

  5. 8.5 Find and correct the error in each of the following code segments:

    1.  

      
      const int ArraySize = 5;
      ArraySize = 10;
      
    2. Assume var b = new int[10];

      
      for (var i = 0; i <= b.Length; ++i)
      {
         b[i] = 1;
      }
      
    3. Assume int[,] a = {{1, 2}, {3, 4}};

      
      a[1][1] = 5;
      
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset