Chapter 10

Answers to Chapter 10 Review Questions

1:
  1. Declare an array variable called distances with elements of type double.

  2. Assign an array object with 5 elements to distances.

  3. Assign an array object to distances with the values 20.1, 30.7, 45.8, 19.1, 12.4, and 34.5.

A1:
  1. private double[] distances;

  2. distances = new double[5];

  3. private double[] distances = {20.1, 30.7, 45.8, 19.1, 12.4, 34.5} ;

2: Consider the following array:
private int[] numbers = { 10,5,3,15} ;
  1. What is the value of the following array element? numbers[1]

  2. What is the output from the following loop construct:

    for(int i = 3; i >= 0; i--)
    {
        Console.Write(" { 0} ", numbers[i])
    }
    
  3. Write a loop using the foreach construct to traverse and print onscreen each element in numbers. This should ...

Get C# Primer Plus 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.