O'Reilly logo

Learning C# 3.0 by Brian MacDonald, Jesse Liberty

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required