Ch. 8 Flashcards
(20 cards)
When dealing with multi-dimensional arrays, each “row” must be the same size.
True.
False.
False
The keyword _________ overrides an existing method with the same signature.
replace
override
overrule
supersede
Override
Consider the array:
s[0] = 7
s[1] = 0
s[2] = -12
s[3] = 9
s[4] = 10
s[5] = 3
s[6] = 6
The value of s[s[6] - s[5]] is:
0
3
9
0
9
The foreach statement is preferred over the for statement when the indices of the elements in an array will be used in the body of the repetition statement.
True.
False.
False
Individual elements of arrays are passed to methods by value.
True.
False.
True
What is the method header for passing in the variable that holds a reference to an array of Strings?
method_name(ref String[] array)
method_name(String[] ref array)
method_name(String[])
None of the above.
method_name(ref String[] array)
What is the proper foreach header format?
(foreach type_identifer in arrayName)
foreach (arrayName)
foreach (type_identifer in arrayName)
None of the above.
foreach (type_identifer in arrayName)
The foreach repetition statement requires that you provide an array and a variable for the purpose of:
preventing the structure from going past the end of the array
storing the value of each element that is traversed
acting as a counter to traverse the array
None of the above.
storing the value of each element that is traversed
Multi-dimensional arrays require two or more indices to identify particular elements.
True.
False.
True
Which expression adds 1 to the element of array arrayName at index i, assuming the array is of type int?
++arrayName[i]
arrayName++[i]
arrayName[i++]
None of the above.
++arrayName[i]
C# automatically performs bounds checking to ensure the program doesn’t access data outside the bounds of an array.
True.
False.
True
The params modifier can be used anywhere in the method’s header.
True.
False.
False
Which of the following sets of statements creates a multidimensional array with 3 rows, where the first row contains 1 value, the second row contains 4 items and the final row contains 2 items?
int[][] items;
items = new int[3][?];
items[0] = new int[1];
items[1] = new int[4];
items[2] = new int[2];
int[][] items;
items = new int[3][];
items[0] = new int[1];
items[1] = new int[4];
items[2] = new int[2];
int[][] items;
items = new int[?][?];
items[0] = new int[1];
items[1] = new int[4];
items[2] = new int[2];
int[][] items;
items[0] = new int[1];
items[1] = new int[4];
items[2] = new int[2];
int[][] items;
items = new int[3][];
items[0] = new int[1];
items[1] = new int[4];
items[2] = new int[2];
Consider the class below:
class Test
{
static void Main()
{
int[] a = {99, 22, 11, 3, 11, 55, 44, 88, 2, -3};
int result = 0;
for (int i = 0; i < a.Length; ++i)
{
if (a[i] > 30)
{
result += a[i];
}
}
Console.WriteLine($”Result is: {result}”);
}
}
The output of this C# program will be:
Result is: 280
Result is: 154
Result is: 286
Result is: 332
Result is: 286
The position number in parentheses is formally called an index.
True.
False.
False
Which of the following statements is false?
You can have many catch blocks to handle different types of exceptions that might be thrown in the corresponding try block.
The runtime performs array bounds checking.
When an exception is thrown, the try block in which it occurs terminates and a corresponding catch block, if there is one, begins executing-if you declared any variables in the try block, they are accessible in the catch block.
The catch block declares an exception parameter’s type and name. The catch block can handle exceptions of the specified type.
When an exception is thrown, the try block in which it occurs terminates and a corresponding catch block, if there is one, begins executing-if you declared any variables in the try block, they are accessible in the catch block.
Which of the following statements creates a multidimensional array with 3 rows, where the first row contains 1 item, the second row contains 4 items and the final row contains 2 items?
int[][] items = {new int {1, null, null, null},
new int {2, 3, 4, 5},
new int {6, 7, null, null}};
int[][] items = {new int {1},
new int {2, 3, 4, 5},
new int {6, 7}};
int[][] items = {new int {1},
new int {2, 3, 4, 5},
new int {6, 7},
new int {});
int[][] items = {new int {1},
new int {4},
new int {2}};
int[][] items = {new int {1},
new int {2, 3, 4, 5},
new int {6, 7}};
Jagged arrays are maintained as arrays of arrays.
True.
False.
True
What can foreach statements iterate through?
arrays
collections
databases
both a and b
both a and b
[C#6] Initializing an auto-implemented property in its declaration is a C# 6 feature known as auto-property initializers. Which of the following is the general syntax for a read-write auto-implemented property with an initializer?
Type PropertyName {get, set;} = initializer;
Type PropertyName {get | set} = initializer;
Type PropertyName {get; set} = initializer;
Type PropertyName {get; set;} = initializer;
Type PropertyName {get; set;} = initializer;