Chapter 15: Strings
Quiz Solutions
Solution to Question 15-1. string
(lowercase) is the C# keyword that maps to the .NET Framework String
class. They may be used interchangeably.
Solution to Question 15-2. IComparable
guarantees that strings can be sorted. ICloneable
guarantees that you can call the Clone
method on a string object and get back a new duplicate string. IConvertible
allows strings to be converted to other types (such as integers). And IEnumerable
guarantees that strings can be iterated over in foreach
loops.
Solution to Question 15-3. A string literal is a quoted string, provided by the programmer, such as “Hello”.
Solution to Question 15-4. An escape character embedded in a string indicates that the character or punctuation that follows is to be treated as an instruction rather than as part of the string. \n
indicates a new line. \"
indicates that the quote symbol is part of the string, not terminating it.
Solution to Question 15-5. Verbatim strings are taken “as is” and thus do not require escape characters. Where \\
would indicate a single backslash in a normal string, in a verbatim string it indicates two backslashes. Verbatim strings must include an @
character before the first double quote.
Solution to Question 15-6. The fact that strings are immutable means they cannot be changed. When you appear to change a string, what actually happens is that a new string is created and the old string is destroyed by the garbage collector if it is no longer referenced.
Solution ...
Get Learning C# 3.0 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.