A.3. Chapter 5

A.3.1. Exercise 1 Solution

A value type variable has its data stored in its rvalue. A reference variable has an rvalue that holds either null or a memory address. If the reference variable currently holds null, it means that the reference variable is not associated with any useful information. If the reference variable holds a valid memory address (i.e., non-null), the rvalue tells you where in memory the information associated with the reference variable is stored.

A.3.2. Exercise 2 Solution

message = message.Replace("Frday", "Friday");

A.3.3. Exercise 3 Solution

There are several ways to solve the bug. First, you could do nothing and say that most people will never notice there's an extra space. Always keep in mind that doing nothing is a decision. Sometimes fixing a bug is so difficult and expensive, it's just not worth the effort. (A major chip manufacturer had a bug "etched" into the firmware for the chip. Because the error was so obscure, the manufacturer simply ignored the problem until enough people complained about it.) Fixing this bug, however, is pretty simple, so we should explore some other alternatives.

Second, you could pad the word to be removed with a leading blank space. As long as the word is not at the beginning of a sentence, this would probably work.

A third alternative is to leave the code as it is but follow it up with a call to the Replace() method. In this case, you would want to find the two blank spaces and replace them with a single ...

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