51. Consider the following code segment:
int[] x = {1, 2, 3, 3, 3};
bool[] b = new bool[x.Length];
for ( int i = 0; i < b.Length; i++ )
b[i] = false;
for ( int i = 0; i < x.Length; i++)
b[ x[i] ] = true;
int count = 0;
for (int i = 0; i < b.Length; i++)
{
if ( b[i] == true )
count++;
}
After the code segment is executed, the value of count would be:
A. 1
B. 2
C. 3
D. 4
E. 5
52. What will be printed?
int x = 4;
if(x > 5)
x = x + 5;
Console.Write("x is " + x);
A. x is 5
B. x is 9
C. x is 4
D. nothing will be printed
53. Exceptions can be trapped by placing the statements that might cause an error in a(n)
_______________ block.
A. find/catch
B. try/fix
C. find/finally
D. try/catch
E. try/finally
54. How many times will the following while loop print the value of x?
int x = 0;
while(x < 10)
{
Console.Write(x.ToString());
x++;
}
A. 0
B. 11
C. 10
D. 9
46. Consider the following code segment:
int[] x = { 0, 1, 2, 3 };
int temp;
int i = 0;
int j = x.Length - 1;
while (i < j)
{
temp = x[i];
x[i] = x[j];
x[j] = 2 * temp;
i++;
j--;
}
After this code is executed, array “x” contains the values:
A. { 3, 2, 2, 0}
B. {0, 1, 2, 3}
C. {3, 2, 1, 0}
D. {0, 2, 4, 6}
E. {6, 4, 2, 0}
56. Consider the following code segment:
int[ ] x1 = {0, 1, 2, 3};
int[ ] x2 = {1, 2, 2, 3};
int i1 = 0;
int i2 = 0;
int count = 0;
while ( (i1 < x1.Length) && (i2 < x2.Length))
{
if ( x1[i1] == x2[i2] )
{
Count++;
i2++;
}
else if (x1[i1] < x2[i2])
{
i1++;
}
else
{ // x1[i1] > x2[i2]
i2++;
}
}
After the code segment is executed in the above code, what will be the value of counter?
A. 0
B. 1
C. 2
D. 3
E. 4
56. To read a text file stored on disk, a C# programmer would need to read the file as:
A. a stream
B. a channel
C. a port
D. a dialog
E. XML