You are on page 1of 7

Starting Out with Visual C#, 5e (Tony Gaddis)

Chapter 3 Processing Data

TRUE/FALSE

1. When you declare a named constant, an initialization value is not required.

ANS: F

2. If you don't write an access modifier in a field declaration, an error will occur.

ANS: F

3. If a field is a variable of a numeric data type, it will be initialized to 0 by default.

ANS: T

4. Only TextBox controls have a TabIndex property.

ANS: F

5. A Panel control cannot display a title and does not have a Text property.

ANS: T

6. The contents of a control's Text property is always a string.

ANS: T

7. In C# you must declare a variable in a program before you can use it to store data.

ANS: T

8. After a variable has been declared, you can use the + operator to store a value in the variable.

ANS: F

9. The purpose of a variable declaration is to tell the compiler that you plan to use a variable of a
specified name to store a particular type of data.

ANS: T

10. An error occurs if a statement in one method attempts to access a local variable declared inside another
method.

ANS: T

11. Variables with the same name cannot be declared in different methods.

ANS: F

12. When you store data in a variable, the value replaces any data previously stored in that variable.
ANS: T

13. You can declare multiple variables of different data types in one program statement.

ANS: F

14. A variable of the decimal data type can hold real numbers with greater precision than the double
data type.

ANS: T

15. You can assign integer constants to int, double, and decimal variables.

ANS: F

16. A cast operator is the name of the desired data type, written inside parentheses and placed to the left of
the value that you want to convert.

ANS: T

17. C# does not allow operations that mix the decimal and double data types unless you use a cast
operator to explicitly convert one of the operands.

ANS: T

18. Any data the user enters into a TextBox control is stored in the control's Text property as a string, even
if it is a number.

ANS: T

19. If all statements in a try block execute with no exception, the catch block is skipped.

ANS: T

20. The using System; directive is required for any program that uses the Parse methods.

ANS: T

MULTIPLE CHOICE

1. A __________ holds only one data value at any given moment in time.
a. program b. data type c. method d. variable
ANS: D

2. Which of the following statements initializes a variable with an integer literal?


a. int score = 2500;
b. decimal total = 156.78m;
c. double rate = 0.00435;
d. string name = "Tony";
ANS: A

3. Appending the letter M or m to a numeric literal causes the number to be considered a __________
literal.
a. monetary b. double c. mnemonic d. decimal
ANS: D

4. Assuming an application has an exception object named ex, which of the following statements would
cause the exception's default error message to be displayed in a message box?
a. MessageBox(ex.Message);
b. ex.Message = MessageBox.Text;
c. MessageBox.Show(ex.Message);
d. MessageBox.Text = ex.Message;
ANS: C

5. A __________ is an identifier for a value that cannot be modified during the program's execution.
a. sentinel c. keyword
b. literal d. named constant
ANS: D

6. If you do not initialize a(n) __________ field, it begins with a special value known as null.
a. int b. decimal c. double d. string
ANS: D

7. The order in which controls receive the focus is called the __________.
a. focus index b. tab order c. order element d. tab index
ANS: B

8. When a user types something into a TextBox control, the input is stored in the control's __________
property.
a. Text b. Input c. String d. Value
ANS: A

9. Which of the following statements assigns the value contained in the Text property of a TextBox
control named ageTextBox to the Text property of a Label control named ageLabel?
a. ageLabel = ageTextBox;
b. ageTextBox.Text = ageLabel.Text;
c. ageLabel.Text = ageTextBox.Text;
d. ageTextBox = ageLabel;
ANS: C

10. Which of the following will declare a variable of type int?


a. var myAge = "23"; c. int myAge = 23.0;
b. var myAge = 23; d. var myAge = 23.0
ANS: B

11. Which of the following statements clears the Text property of a TextBox control named
addressTextBox?
a. addressTextBox.Text = Text.Clear;
b. addressTextBox.Text = "";
c. addressTextBox = Nothing;
d. addressTextBox.Empty();
ANS: B

12. Fundamental types of data, such as integers and real numbers are known as __________ data types.
a. fundamental b. primitive c. natural d. basic
ANS: B

13. Assuming a string variable named city has already been declared, which of the following
statements assigns the string literal Vienna to the variable?
a. "Vienna" = city; c. city("Vienna");
b. city + "Vienna"; d. city = "Vienna";
ANS: D

14. Assuming a string variable named movieTitle has already been declared, which of the
following statements combines the strings The and Hobbit and then assigns the resulting string to
the variable with a space between the two words?
a. movieTitle("The ", "Hobbit");
b. "The " + "Hobbit" = movieTitle;
c. movieTitle = "The " & "Hobbit";
d. movieTitle = "The " + "Hobbit";
ANS: D

15. A __________ variable belongs to the method in which it is declared and only statements inside that
method can access the variable.
a. limited b. local c. global d. static
ANS: B

16. Which of the following statements initializes a variable named color with the string red?
a. color = "red";
b. string color = "red";
c. "red" = string color;
d. string color("red";
ANS: B

17. Which of the following statements declares the string variables city, state, and zip using a
single declaration statement?
a. string city, state, zip;
b. string city; string state; string zip;
c. string city; state; zip;
d. string city state zip;
ANS: A

18. When an operation is performed on two int values, the result will be a(n) __________.
a. decimal b. double c. string d. int
ANS: D

19. When an operation involves an int and a decimal, the result will be a(n) __________.
a. decimal b. double c. string d. int
ANS: A

20. The __________ data type is used to store any number that might have a fractional part.
a. string b. int c. double d. boolean
ANS: C

21. Given the following code segment, what value is assigned to the half variable?
int distance; //declare distance as an int
double half; // declare half as a double
distance = 35; // assign 35 to distance
half = distance / 2; // calculate half the distance
a. 70 b. 17.5 c. 18 d. 17
ANS: D

22. To convert the contents of a string to any of the numeric data types, we use a family of methods in
the .NET framework known as the ___________methods.
a. Convert b. itoa c. ToString d. Parse
ANS: D

23. A data value (variable or constant) passed into a method is known as a(n) __________.
a. argument b. delimiter c. descriptor d. factor
ANS: A

24. A(n) __________ is an unexpected error that occurs when a program is running, causing the program
to halt if the error is not properly dealt with.
a. bug c. logic error
b. exception d. illegal operation
ANS: B

25. Which of the following is the correct way to call the ToString method.
a. ToString.variableName()
b. ToString(variableName)
c. variableName.ToString()
d. To.variableName.String()
ANS: C

26. When you pass the formatting string __________ to the ToString method, the number is returned
formatted as currency.
a. "C" or "c" c. "D" or "d"
b. "F" or "f" d. "P" or "p"
ANS: A

27. In C# an exception handler is written with the __________ statement.


a. try-catch c. run-break
b. catch-try d. break-run
ANS: A

28. In code, you move the input focus by calling the __________ method.
a. Move b. Tab c. Selection d. Focus
ANS: D

29. Which of the following statements changes the form's BackColor property to Blue?
a. this.Color = Blue;
b. this.BackColor = Color.Blue;
c. Form1.BackColor = Blue;
d. Me.BackColor(Blue);
ANS: B

30. Which of the following causes the debugger to stop on a specific statement while a program is
running?
a. stopping line b. breakpoint c. set point d. line break
ANS: B

31. The __________ window in the debugger allows you to type the debugging commands using the
keyboard.
a. watch b. expert c. command d. immediate
ANS: D

32. Controls that display text have a __________ property that allows you to change the color of the text.
a. TextColor b. ForeColor c. FontColor d. Color
ANS: B

33. The __________ property lets you designate a button on a form that will be clicked automatically
when the user presses the Enter key.
a. ConfirmButton c. EnterButton
b. AcceptButton d. DefaultButton
ANS: B
34. When you call the ToString method, you can optionally pass a(n) __________ as an argument to
the method to indicate that you want the number to appear formatted in a specific way when it is
returned as a string.
a. formatting string c. output value
b. style specifier d. design element
ANS: A

35. The __________ method can be used to convert a string to a decimal.


a. decimal.ToString c. ToString.decimal
b. Parse.decimal d. decimal.Parse
ANS: D

36. A math expression involving a double and a(n) __________ is not allowed unless a cast operator is
used to convert one of the operands.
a. int b. double c. decimal d. boolean
ANS: C

37. Parts of a mathematical expression may be grouped with __________ to force some operations to be
performed before others.
a. parentheses c. braces
b. double quotation marks d. semicolons
ANS: A

38. The __________ dictates which operations are performed first in a mathematical expression.
a. least significant value c. compiler version
b. order of operations d. operator position
ANS: B

39. The values on the right and left sides of a math operator are called __________.
a. expressions b. algorithms c. operands d. factors
ANS: C

40. You can use a(n) __________ to explicitly convert a value from one numeric data type to another,
even if the conversion might result in loss of data.
a. cast operator c. data binding
b. conversion formula d. explicit operator
ANS: A

You might also like