O'Reilly logo

C# Primer Plus by Klaus Michelsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required