final Flashcards
The ________ is used to perform string concatenation.
&
In a program, you clear a text box with code ________________.
by assigning the empty string to the text property
Variables declared within a button’s click-event are ____________ variables
local
What has the highest order of precedence in arithmetic expressions?
Exponentiation
A ______ control can display arrays in a scrollable grid.
DataGridView
The result of the following is __.
string str = “Spring”;
char c = str[2];
MessageBox.Show(c.ToString());
r
A(n) __________ is an object that can hold a group of values that are all of the same data type.
array
Each element in an array is assigned a unique number known as a(n) _____________.
subscript or index
Given the following code, which can find the maximum value in the array?
int[] n = { 16, 3, 7, 18, 21 };
a)
int max = n[0];
for (int i = 1; i < n.Length-1; i++)
{ if (n[i] > max)
{ max = n[i]; }
}
b)
int max = n[0];
for (int i = 1; i < n.Length; i++)
{ if (n[i] > max)
{ max = n[i]; }
}
c)
int max = n[0];
for (int i = n.Length-1; i>=1; i–)
{ if (n[i] < max)
{ max = n[i]; }
}
d)
int max = n[1];
for (int i = n.Length-1; i>=1; i–)
{ if (n[i] < max)
{ max = n[i]; }
}
b)
int max = n[0];
for (int i = 1; i < n.Length; i++)
{ if (n[i] > max)
{ max = n[i]; }
}
The result of the following is _____.
int a = 5;
int b = 7;
int c = a;
a = b;
b = c;
MessageBox.Show(“a = “ + a + “, b = “ + b);
a) a = a, b = b
b) a = 5, b = 7
c) a = 7, b = 5
d) a = b, b = a
c) a = 7, b = 5
What loop performs an iteration before testing its Boolean expression?
do-while
What method will erase all the items in a listbox?
items.Clear();
You want to determine whether a variable, payAmount , is between 1200 and 1400 inclusively (1200 & 1400 included).
If the value is in the range the label lblMessage should contain the string “Pay amount is in the range”.
Which of the following code segments will accomplish this?
a)
if (payAmount >= 1200 && <= 1400)
{
lblMessage.text = “Pay amount is in the range”;
}
b)
if (payAmount >= 1200 || payAmount <= 1400)
{
lblMessage.text = “Pay amount is in the range”;
}
c)
if (payAmount >= 1200 && payAmount <= 1400)
{
lblMessage.text = “Pay amount is in the range”;
}
d)
if (payAmount > 1200 && payAmount < 1400)
{
lblMessage.text = “Pay amount is in the range”;
}
c)
if (payAmount >= 1200 && payAmount <= 1400)
{
lblMessage.text = “Pay amount is in the range”;
}
What is the purpose of using the following type of structure?
try
{ some statements; }
catch
{ some statements; }
to catch any run-time errors such as divide-by-zero and not have the program shut down or crash
What is the value of outCome after the following section of code is executed?
decimal A = 6.0m;
double B = 2.0;
double C = 3 * (double)A/B;
double outCome = 2 * C + 15;
33.0
When the user selects a file with the Open dialog box, the file’s path and filename are stored in the control’s ________.
Filename property
The _______ displays a standard Windows Save As dialog box.
SaveFileDialog control
What is the difference between a void method and a value-returning method?
A value-returning method must return a value back through its name and a void method cannot.
When you want to write data to a text file, you use the __________ class.
StreamWriter
When you want to read data from a text file you use the _____________ class.
StreamReader
StreamReader objects have a Boolean property named ______________ that signals whether the end of a text file has been reached.
EndOfStream
What is the output of the following code?
int a = 5;
int b = 10;
SwitchValues(ref a,ref b);
MessageBox.Show(“a=”+a +” “+”b=”+ b);
public void SwitchValues(ref int a,ref int b)
{
int temp = a;
a = b;
b = temp;
}
a) a=5 b=10
b) a=10 b=5
c) a=a b=b
d) a=b b=a
b) a=10 b=5
The modulus operator (%) computes the remainder after dividing its first operand by its second. For example 3 % 2 is 1 and 4 % 2 is 0. What is the output of the following code?
(Hint: Write it down and don’t do it in your head.)
int[] a = new int[10];
int count=0;
for (int index = 0; index < a.Length; index++)
{ a[index] = index + 1; }
for (int index = 0; index < a.Length; index++)
{
if (a[index] % 2 == 0)
{ count++; }
}
MessageBox.Show(“count=” + count);
c) count = 5
According to the following, which statement is correct?
StreamWriter outputFile;
outputFile = File.CreateText(“data.txt”);
string[] subject = { “Biology”, “Chemistry”, “Physics” };
for (int i=0; i<subject.Length; i++)
{ outputFile.WriteLine(subject[i]); }
outputFile.Close();
The three elements of subject array will be written to the “data.txt” file’s contents.
The money data type is the _______ data type defined in C#.
decimal
true or false?
string str = “1a3b5”;
if (char.IsDigit(str, 2))
{ MessageBox.Show(“True”); }
else
{ MessageBox.Show(“False”); }
true
What does the messagebox show?
string str = “chocolate ice cream”;
int position = str.IndexOf(“ice”);
if (position != -1)
{ MessageBox.Show(position.ToString()); }
9
- true or false?
Before adding an item to listbox the size of the listbox must be known first.
false
What is the value of i at the conclusion the loop?
int i=0;
while (i<3)
{ i++; }
3
What is the value of oneDollar?
double amount=20;
decimal oneDollar;
oneDollar = 5 * amount;
logical error
You can use the ______________ property to determine whether an item is selected in a ListBox.
SelectedIndex
What loop is a pretest that first initializes a counter variable and then increments the counter variable at the end of each iteration?
for
Which of the following code is a correctly written value-returning method Average that will accept three integers as parameters, calculate their average, and return the result?
a)
private double average(int a, int b, int c)
{ average = (a + b + c)/3.0; }
b)
private double average(out int a, out int b, out int c)
{ average = (a + b + c)/3.0; }
c)
private double average (int a, int b, int c, double average)
{ average = (a + b + c)/3.0; }
d)
private double average(int a, int b, int c)
{ return (a + b + c)/3.0; }
d)
private double average(int a, int b, int c)
{ return (a + b + c)/3.0; }
A ListBox object has a ____________ that holds the number of items stored in the ListBox.
Count property