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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access