2.5. Preview Questions#
Complete these questions before class to prepare for the chapter. Use the dropdowns to check your answers.
2.5.1. True or False#
1. In C#, int can store decimal values such as 3.14.
Answer
False — int is a whole-number type; use double or float for decimals.
2. The string type in C# is a reference type.
Answer
True — Strings are objects on the heap, accessed by reference.
3. Integer division in C# always produces a double result.
Answer
False — Integer division truncates to int; cast one operand to get a double.
4. Console.ReadLine() returns a string value.
Answer
True — All console input arrives as string; parse it to convert to other types.
5. The + operator works for both arithmetic addition and string concatenation.
Answer
True — C# overloads + for numeric addition and string joining.
6. If you add a helper file ui.cs to your project folder, you now have two entry points.
Answer
False — Adding a .cs file that defines a helper class does not create a new entry point. A project still has only one Main(). Only if ui.cs also declared its own Main() would you have a conflict — and the compiler would reject it.
2.5.2. Multiple Choice#
1. Which data type stores a true or false value?
a) int
b) bit
c) bool
d) byte
Answer
c) bool — bool is the boolean type in C#.
2. What is the result of 7 / 2 when both operands are integers?
a) 3.5
b) 3
c) 4
d) 7.2
Answer
b) 3 — Integer division truncates the fractional part, giving 3.
3. Which expression converts a string to an integer?
a) int.Convert(s)
b) Convert.ToInt32(s)
c) string.ToInt(s)
d) Parse.Int(s)
Answer
b) Convert.ToInt32(s) — Convert.ToInt32() (or int.Parse()) converts a string to int.
4. What is the scope of a variable declared inside a method?
a) Global
b) File-level
c) Class-level
d) Local to the method
Answer
d) Local to the method — Method-local variables exist only within that method’s block.
5. Which escape sequence represents a newline character in a C# string?
a) \t
b) \r
c) \n
d) \
Answer
c) \n — \n inserts a newline; \t is a tab, \r is carriage return.
Footnotes