8.1 Fill in the blank(s) in each of the following statements:
Lists and tables of values can be stored in .
An array is a group of (called elements) containing values that all have the same .
The statement allows you to iterate through the elements in an array without using a counter.
The number that refers to a particular array element is called the element’s .
An array that uses two indices is referred to as a(n) array.
Use the foreach
header to iterate through double
array numbers
.
Command-line arguments are stored in .
Use the expression to receive the total number of arguments in a command line. Assume that command-line arguments are stored in args
.
Given the command MyApp test
, the first command-line argument is .
A(n) in the parameter list of a method indicates that the method can receive a variable number of arguments.
As of C# 6, you can declare auto-implemented properties, which are read-only properties.
8.2 Determine whether each of the following is true or false. If false, explain why.
A single array can store values of many different types.
An array index should normally be of type float
.
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.
Command-line arguments are separated by commas.
Auto-implemented properties cannot be initialized in their declarations.
8.3 Perform the following tasks for an array called fractions
:
Declare constant ArraySize
initialized to 10
.
Declare variable fractions
which will reference an array with ArraySize
elements of type double
. Initialize the elements to 0
.
Name the element of the array with index 3.
Assign the value 1.667
to the array element with index 9.
Assign the value 3.333
to the array element with index 6.
Sum all the elements of the array, using a for
statement. Declare integer variable x
as a control variable for the loop.
Sum all the elements of the array, using a foreach
statement. Declare double
variable element
as a control variable for the loop.
8.4 Perform the following tasks for an array called table
:
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
.
How many elements does the array contain?
Use a nested for
statement to initialize each element of the array to the sum of its indices.
8.5 Find and correct the error in each of the following code segments:
const int ArraySize = 5;
ArraySize = 10;
Assume var b = new int[10];
for (var i = 0; i <= b.Length; ++i)
{
b[i] = 1;
}
Assume int[,] a = {{1, 2}, {3, 4}};
a[1][1] = 5;