# 7 and Array

Topics: 7, Data type, Dunlap broadside Pages: 3 (500 words) Published: May 20, 2013
1. An array is a list of data items that _____.
are of different data types
are all integers
have different names
are indexed |
2. An array that stores five days of closing stock prices can be declared as _____. decimal price1, price2, price3, price4, price5;
decimal [] price = new decimal[5];
decimal price[] = new decimal[5];
decimal [] price = new price[5];|

int [] myArray = {1,4,3,5,6};

It declares a 5 dimensional array.
The size of the array is five.
It sets the element myArray[1] to 1.
It won't compile due to a syntax error.|
4. Given the following declaration, what is/are the value(s) of height[1,1]?

double[,] height = { {2.1, 3.2, 6.5, 7.2},
{5.4, 6.7, 3.5, 3.6} };

2.1
2.1 5.4
3.2 6.7
6.7|
5. In the following code, the "foreach" statement _____.

int[] size = {2,3,5,6,4,5};
foreach (int
val in size)
Console.Write("{0} ",val);
can read and write data to each array element
iterates through each element of the array
returns the memory address of each array element
prints the index of each array element|
6. What will be the output of this code?

int[] size = {2,3,5,6,4,5};
Array.Sort(size);
foreach (int
val in size)
Console.Write("{0} ", val);

2 3 5 6 4 5
5 4 6 5 3 2
6 5 5 4 3 2
2 3 4 5 5 6 |
7. When a single array element, such as myArray[2], is passed to a method, the method receives _____. the starting address of the array
a copy of the value the element stores
a copy of the array|
8. To pass the entire myData array to the DisplayItems method, replace the commented line below with _____.

static void
Main()
{
int[] myData = {1,2,3,4};
//call DisplayItems
}
public static void DisplayItems(params
int[] item)
{
for (int i=0; i<item.Length; i++)
Console.Write("{0} ",item[i]);
}

DisplayItems(myData);
DisplayItems(myData[0]);
DisplayItems(ref myData);
DisplayItems(1,2,3,4);|
9. The...