1/145
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
Exceptions are objects that are created from the _________________ class or one of its subclasses.
Exception
When compared to untyped collections, typed collections reduce:
the number of runtime errors and the amount of casting that's required
Which of the following is not true about the null-conditional operator?
It can only be used with reference types.
What is the value of the variable named s2 after the following statements are executed?
string s1 = "abcdefg";
string s2 = "";
for (int i = 0; i < s1.Length; i+=2)
{
s2 += s1[i];
}
aceg
To convert a StringBuilder object to a String, you can use:
the ToString() method of the StringBuilder object
What happens to radio buttons that are not placed in a group box?
They function as a separate group.
To cancel the FormClosing event of a form, you can:
set the Cancel property of the CancelEventArgs object to true
What keyword do you code at the beginning of a method if you only want it to be available within the current class?
private
What keyword do you code for the return type of a method that doesn't return any data
void
For each parameter in the parameter list for a method, you must code:
the data type of the parameter followed by the name of the parameter
When you call a method, the arguments you pass to it:
must be declared with data types that are compatible with the parameters
If you pass a variable by value, the called method:
can't change the value of the variable in the calling method
If you declare a parameter for a method is optional:
the parameter must be assigned a default value
To generate an event handler for a control event, you can display the Events list for the control and then:
double-click on the event
To generate a method call and a method from existing code, you can use a feature called:
refactoring
To define a tuple as the return type for a method, you define its members by separating them with commas and enclosing them in...
parentheses - ()
If you have an int variable named yrs and two decimal variables named prin and rate, which statement can you use to call the method with the following method declaration?
private decimal GetInterest(int years, decimal interestRate, decimal principle)
decimal interest = GetInterest(yrs, rate, prin);
If the following GetInterest() method uses a decimal variable named interest to store the interest amount, which statement can you use to return the interest amount?
private decimal GetInterest(int years, decimal interestRate, decimal principle)
return interest;
Which of the following declares a private method named GetMessage() that returns a string value and requires a string parameter named fullName and a decimal parameter named currentBalance?
private string GetMessage(string fullName, decimal currentBalance)
Given a text box named txtNum, which of the following statements may cause a format exception?
decimal d = Convert.ToDecimal(txtNum.Text);
The list of methods that were called before an exception occurred is called the:
StackTrace
In a try-catch statement, the finally block is executed:
whether or not an exception occurs or a catch block is executed
When validating data entered into the text boxes of a form, it is not common to check whether:
all text entries are non-numeric
The code within a catch block is executed when:
the code in the try block throws an exception
Consider the code that follows. What does it do?
string value = "2";
try
{
int num = Convert.ToInt32(value);
}
MessageBox.Show("Valid integer");
catch(FormatException)
{
MessageBox.Show("Invalid integer");
}
The code doesn't compile
Consider the following code:private void btnCalculate_Click(object sender, System.EventArgs e)
{
decimal weightInPounds = 0m;
try
{
weightInPounds = Convert.ToDecimal(txtPounds.Text);
if (weightInPounds > 0)
{
decimal weightInKilos = weightInPounds / 2.2m;
lblKilos.Text = weightInKilos.ToString("f2");
}
else
{
MessageBox.Show("Weight must be greater than 0.", "Entry error"); txtPounds.Focus();
}
}
catch(FormatException)
{
MessageBox.Show("Weight must be numeric.", "Entry error"); txtPounds.Focus();
}
}
If the user enters "200#" in the text box and clicks the Calculate button, what does the code do?
It displays a dialog box with the message "Weight must be numeric."
Consider the following code: private void btnCalculate_Click(object sender, System.EventArgs e)
{
decimal weightInPounds = 0m;
try
{
weightInPounds = Convert.ToDecimal(txtPounds.Text);
if (weightInPounds > 0)
{
decimal weightInKilos = weightInPounds / 2.2m;
lblKilos.Text = weightInKilos.ToString("f2");
}
else
{
MessageBox.Show("Weight must be greater than 0.", "Entry error"); txtPounds.Focus();
}
}
catch(FormatException)
{ MessageBox.Show("Weight must be numeric.", "Entry error"); txtPounds.Focus();
}
}
If the user enters 118 in the text box and clicks the Calculate button, what does the code do?
It calculates the weight in kilograms.
To refer to the ninth element in a one-dimensional array named sales, you code:
sales[8]
To refer to the second column in the fourth row of a rectangular array named vendors, you code:
vendors[3,1]
Which of the following statements creates an array of decimals named miles and assigns the values 27.2, 33.5, 12.8, and 56.4 to its elements?
decimal[ ] miles = {27.2m, 33.5m, 12.8m, 56.4m};
Which of the following for statements adds each element in a one-dimensional array named totals to a string named message?
for (int i = 0; i < totals.Length; i++) message += totals[i] + "|";
Which of the following is not true about collections?
Some collections use indexes that start with 1.
Which of the following is NOT true about a SortedList collection?
Key values must be added to a sorted list in alphabetical order.
A queue provides:
a Dequeue() method for getting the next item in the collection
Assuming the computer's regional settings are configured for the United States, which of the following statements creates a DateTime value whose date is set to March 28, 2021?
DateTime date = DateTime.Parse("03/28/2021");
Which of the following statements creates a DateTime value named dueDate that's set to the date December 31, 2021?
DateTime dueDate = new DateTime(2021, 12, 31);
Which property of the DateTime structure returns the current date with the time set to 12:00:00 AM?
Today
Which statement creates a DateTime value named invoiceDate that's set to the current date and time?
DateTime invoiceDate = DateTime.Now;
What is the value of startDate after the following statements are executed?
DateTime startDate = new DateTime(2021, 3, 1);
startDate = startDate.AddMonths(3);
June 1, 2021
What date is represented by d3 after these statements are executed?
DateTime d1 = new DateTime(2021, 3, 1);
DateTime d2 = new DateTime(2021, 3, 4);
TimeSpan t = d2.Subtract(d1);
DateTime d3 = d1.Add(t);
March 4, 2021
What method of the String class lets you format numbers, dates, and times?
Format()
What method can you use to remove spaces from the beginning and end of a string?
Trim()
Given the string variable that follows, which statement removes the spaces from the string and stores the result in the same string variable?
string lastName = " wilson ";
lastName = lastName.Trim();
Which of the following statements refers to the second character in a String object named address?
char c = address[1];
What is the value of the variable named s after the following statements are executed?
string fullName = "Miller, Edward";
int i = fullName.IndexOf(",");
string s = fullName.Substring(0, i);
Miller
What is the value of the variable named s after the following statements have been executed?
string fullName = "Miller, Edward";
int i = fullName.IndexOf(",");
string s = fullName.Substring(i + 1);
Edward
What is the value of the variable named s2 after the following statements have been executed?
string s1 = "The quick brown fox";
string[] words = s1.Split(' ');
string s2 = words[words.Length - 1];
fox
Given the following StringBuilder object named cn, which statement adds -9326 to it?
StringBuilder cn = new StringBuilder("2375-3847-8455");
cn.Append("-9326");
What is the value of the variable named s after the following statements are executed?
decimal d = 3892.22m;
string s = $"{d:##,##0.00;(##,##0.00)}";
3,892.22
What control do you use to create a group of radio buttons?
group box
What will the cboNumbers combo box contain if the following method is called twice?
private void Fill()
{
for (int i = 1; i < 5; i++)
{
cboNumbers.Items.Clear(); cboNumbers.Items.Add(i);
}
}
4
To change the name of a form, you can change the name of the form in the Solution Explorer and then:
let Visual Studio automatically change any other uses of the form name
You can use the Tag property of a form to get or set:
Any type of data
What will the following method return?
private string GetName(int customerID, bool readOnly)
A string
The signature of a method is formed by the:
name of the method and its parameter list
If you pass a variable by reference, the called method:
can change the value of the variable in the calling method
Which of the following code snippets passes an argument by name?
subtotal:subtotal
Which of the following is NOT an advantage of passing arguments by name?
You don't have to know the name of the associated parameter
Once you display the list of events for a control, you can wire an existing event handler to any event by:
selecting the event handler from the drop-down list for the event
When coding an expression-bodied method, what operator do you code after the method signature?
lambda operator (=>)
To delete an event handler, you not only have to delete its method but also its:
event wiring
Which of the following statements would you use to call a private method named InitializeVariables() that accepts no parameters and doesn't return a value?
InitializeVariables();
Which of the following statements would you use to pass a variable named message by reference to a method named DisplayMessage?
DisplayMessage(ref message);
Which statement calls a method in the current form named SetButtons() and passes it a false value?
this.SetButtons(false);
Which of the following declares a method named GetMessage() that returns a string value and requires one decimal parameter named currentBalance and is only available within the current form?
private string GetMessage(decimal currentBalance)
Which of the following is a shorter way to code the following GetTotal() method?
private decimal GetTotal(decimal subtotal, decimal tax)
{
return subtotal + tax;
}
private decimal GetTotal(decimal subtotal, decimal tax) => subtotal + tax;
Which of the following declares a method named GetTotals() that returns a tuple that has two members named TotalQty and TotalAmt?
private (int TotalQty, decimal TotalAmt) GetTotals(int year) {}
Which of the following statements would be used to wire the Click event of a button named btnClear to an event handler named ClearControls()?
this.btnClear.Click += new System.EventHandler(this.ClearControls);
The process of checking user entries to make sure they're valid is called:
data validation
If a value that's assigned to an int variable is too large to be stored in it, what type of exception occurs?
OverflowException
If a text box entry can't be converted to a numeric data type, what type of exception occurs?
FormatException
To display a dialog box, you can use the Show() method of:
the MessageBox class
In a try-catch statement, a catch block for the Exception class can be used to catch:
any exceptions that aren't caught by previous catch blocks
Two properties of an object created from the Exception class are:
Message and StackTrace
When you catch an exception, which of its properties can you use to get a description of it?
Message
When you catch an exception, what method can you use to get the type of the exception?
GetType()
What statement causes an exception to occur?
to throw
You typically do NOT throw an exception:
when invalid data is detected
An OverflowException can be avoided by a type of data validation known as:
range checking
You may want to code generic methods for data validation because:
they allow you to reuse your data validation code
To determine the cause of an exception, you can:
all of the above
Which method of the Decimal class returns a false value if the entry can't be converted instead of throwing an exception?
TryParse()
Consider the following code:
private void btnCalculate_Click(object sender, System.EventArgs e)
{
decimal weightInPounds = 0m;
try
{
weightInPounds = Convert.ToDecimal(txtPounds.Text);
if (weightInPounds > 0)
{
decimal weightInKilos = weightInPounds / 2.2m;
lblKilos.Text = weightInKilos.ToString("f2");
}
else
{
MessageBox.Show("Weight must be greater than 0.", "Entry error"); txtPounds.Focus();
}
}
catch(FormatException)
{
MessageBox.Show("Weight must be numeric.", "Entry error"); txtPounds.Focus();
}
}
What type of data validation does this program do?
It displays a dialog box with the message "Weight must be numeric."
Consider the following code:
private void btnCalculate_Click(object sender, System.EventArgs e)
{
decimal weightInPounds = 0m;
try
{
weightInPounds = Convert.ToDecimal(txtPounds.Text);
if (weightInPounds > 0)
{
decimal weightInKilos = weightInPounds / 2.2m;
lblKilos.Text = weightInKilos.ToString("f2");
}
else
{
MessageBox.Show("Weight must be greater than 0.", "Entry error"); txtPounds.Focus();
}
}
catch(FormatException)
{ MessageBox.Show("Weight must be numeric.", "Entry error"); txtPounds.Focus();
}
}
If the user clicks the Calculate button without entering data in the text box, what does the code do?
It displays a dialog box with the message "Weight must be numeric."
Consider the following code:
private void btnCalculate_Click(object sender, System.EventArgs e)
{
decimal weightInPounds = 0m;
try
{
weightInPounds = Convert.ToDecimal(txtPounds.Text);
if (weightInPounds > 0)
{
decimal weightInKilos = weightInPounds / 2.2m;
lblKilos.Text = weightInKilos.ToString("f2");
}
else
{
MessageBox.Show("Weight must be greater than 0.", "Entry error"); txtPounds.Focus();
}
}
catch(FormatException)
{ MessageBox.Show("Weight must be numeric.", "Entry error"); txtPounds.Focus();
}
}
If the user enters -1 in the text box and clicks the Calculate button, what does the code do?
It displays a dialog box with the message "Weight must be greater than 0."
When a statement within a try block causes an exception, the remaining statements in the try block:
aren't executed
When you declare and initialize the values in an array, you are actually creating an instance of what class?
Array
Which of the following foreach statements adds each element in a one-dimensional array named totals to a string named message?
foreach (decimal total in totals) message += total + "|";
Which of the following statements declares a valid rectangular array?
string[,] js = new string[4,4];
Which of the following statements declares a valid jagged array?
string[ ][ ] js = new string[4][ ];
Which of the following statements gets the number of strings in the array that follows?
string[] customers = new string[55];
int size = customers.Length;
Which of the following method declarations is valid for a method that accepts an array of strings named customerNames?
private void ParseCustomerNames(string[] customerNames){}
Which of the following statements sorts a one-dimensional array named values?
Array.Sort(values);
You can use the BinarySearch() method of the Array class to:
search for a value in a sorted array and return the index of that value
Which .NET feature is used by typed collections but not by untyped collections?
Generics
Which of the following statements declares a typed List collection named dueDays that will hold int values?
List
Given a typed List collection of int values named dueDays, which of the following statements adds the value 120 to the end of the list?
dueDays.Add(120);
What is the value of kilos[1] after the code that follows is executed?
decimal[] kilos = {200, 100, 48, 59, 72};
for (int i = 0; i < kilos.Length; i++)
{
kilos[i] *= 2.2;
}
220.0
What is the value of lists after the statements that follow are executed?
string[,] names = new string[200,10];
int lists = names.GetLength(0);
200
What is the value of times[2,1] in the array that follows?
decimal[,] times = { {23.0, 3.5}, {22.4, 3.6}, {21.3, 3.7} };
3.7