Errata for C# Primer Plus (First Printing)

 

Last Updated 23 January, 2002

 

 

* Page 18: The first paragraph of the section called “Compiling C# Source Code in .NET” should have the text:

 

Figure 1.6 of

 

added, so that the text reads:

 

The traditional compilation process for converting the source code of high-level languages into executable programs as described in Figure 1.6 on page 17 has several disadvantages. Two of these are discussed next.

 

 

* Page 20: The last couple of lines in the second paragraph should have (MSIL) added so that they read:

 

As a result, we only ever need to compile our high-level languages into one, non-changing language (MSIL). This solves problem 1 mentioned earlier.

 

 

* Page 38, Figure 2.5: The three lower most boxes in Figure 2.5 (with the text:

 

JIT-Compiler

Machine Language (Native Code)

Execution of Machine Language by Computer

 

Should appear dimmed.

 

 

* Page 46. The word WinForms appears three times on this page (line 1 and the third paragraph). Each appearance should be replaced by the two words: Windows Forms.

 

 

* Page 51: The highlighted text Shakespeare.cs on the second last line on this page should be changed to:

 

"Shakespeare.cs"

 

 

* Page 96: The figure on the top of the page, showing a method definition, should be removed.

 

 

* Page 105: The last two lines of the Tip box currently looks like:

 

20:         Console.WriteLine("The maximum number is: " +

            Math.Max(x, y));

 

The last line should be indented to look like:

 

20:         Console.WriteLine("The maximum number is: " +

                Math.Max(x, y));

 

 

* Page 122: The description of line 43 (43: The Person decides on which floor “he” or “she”…) should be changed to line 45.

 

 

* Page 122: The third line in the description of line 51 begins with the text:

 

(or a composition)

 

This should be changed to:

 

(or an aggregation)

 

 

* Page 128: The third bullet under the headline: Letting an Elevator Object Receive and Fulfill Passenger Requests currently reads:

 

- Update the totalFloorsTraveled statistic (lines 21-22)

 

The line numbers in the parenthesis should be changed to (lines 22-23).

 

 

* Page 160: The int interval in Figure 6.6 currently reads:

- 2147483648

                       to

- 2147483648

 

The last minus sign should be removed:

 

- 2147483648

                       to

2147483648

 

 

* Page 166: Figure 6.11: The arrow pointing at totalMinutesOnMobile is currently marked:

               of type int

 

This should be changed to:

 

               of type uint

 

 

 

* Page 170: The following two lines are found in the middle of this page:

 

01:    long mySum;

02:    mySum = 2147483647 + 1;

 

The first of these lines should be changed to:

 

01:    int mySum;

 

 

* Page 173: The second last line before The Blipos Clock headline currently reads:

 

new comparison operators, the type cast, and the while loop….

 

The word cast should not appear in a special text style.

 

 

 

* Page 178. Listing 6.8 Line 92 is missing a right parenthesis and should look like:

 

92:    myClock.SetSeconds(Convert.ToByte(Console.ReadLine()));

 

 

 

* Page 178. Listing 6.8 Line 94 is missing a right parenthesis and should look like:

 

94:    myClock.SetMinutes(Convert.ToInt16(Console.ReadLine()));

 

 

* Page 178: Listing 6.8 Lines 95 and 96 are missing a few uppercase letters and should instead read as follows:

 

95:     Console.WriteLine("Enter (F)orward (B)ackward " +

96:         "(A)dd fifty (D)educt fifty (T)erminate");

 

 

* Page 179: Line 5 should read:

 

Enter (F)orward (B)ackward (A)dd fifty (D)educt fifty (T)erminate

 

 

* Page 185: The second line in the second note box on this page contains the following expression in the first bullet:

 

-1.5E-45 > x > 1.5E-45

 

The greater than symbols should be replaced by smaller than symbols:

 

-1.5E-45 < x < 1.5E-45

 

 

Similarly the second bullet of this same note box contains the following expression in the second line:

 

-5.0E-324 > x > 5.0E-324

 

The greater than symbols should also here be replaced by smaller than symbols:

 

-5.0E-324 < x < 5.0E-324

 

 

* Page 188: Delete the last sentence in the Tip box that looks like:

 

Alternatively, when comparing values for equality, you should allow for a certain range of inaccuracy.

 

 

* Page 196: The seventh line under the headline Formatting Numeric Values currently reads:

 

mas, the use of scientific notation and a limited  number of decimal digits, it is possible to

 

The word decimal should not be in a special text style.

 

 

* Page 204: The second line contains the text:

 

distance[ts]mass

 

[ts] should be exchanged with * to read:

 

distance * mass

 

 

* Page 207, Figure 7.1:

 

The second line from the bottom of Figure 7.1 reading: 340 + 70 should be erased along with the curly brace underneath this line.

 

 

* Page 211: The text exerciseTimePerson1 in Line 1 should be changed to exercisePerson1 so that line 1 looks like:

 

AverageExerciseTime = (exercisePerson1 + exercisePerson2) / 2;

 

 

* Page 217: The third line from the bottom of the page currently reads:

 

-count is the first operation to take place that is intuitively how we understand…

 

This should be changed to:

 

-count is the first operation to take place. This is intuitively how we understand…

 

 

* Page 225: Figure 7.4 in the second line should be changed to Figure 7.6.

 

 

* Page 232: The first line of the second paragraph in the section called Enumerated Constants contains the words:

 

For example if you want to represent the five colors just mentioned, you can declare

 

The two words:

 

just mentioned

 

in this line should be replaced by:

 

green, blue, red, yellow, and purple

 

 

* Page 255: The first line reads:

 

assigned back to myText in line 25…

 

25 should be changed to 26:

 

assigned back to myText in line 26.

 

 

* Page 257: In the third line of the last paragraph num1 should be exchanged with numA, num2 should be exchanged with numB, num3 should be exchanged with numC

 

 

* Page 258, listing 7.9, line 5: num2 should be exchanged with numB, num3 should be exchanged with numC.

 

 

* Page 264, Figure 7.9: The arrow that originates at wordEnd and currently points at index 1 should instead point at index 0.

 

 

* Page 287: The fourth line currently reads:

 

can, with certainty, conclude that 5000  balance  20000. This is…

 

A couple of <= needs to be added to form:

 

can, with certain, conclude that 5000 <= balance <= 20000. This is…

 

 

* Page 289: The last line of the second paragraph currently reads:

 

turn, this allows us to deduce that (60000  balance  75000).

 

Two <= symbols should be added:

 

turn, this allows us to deduce that (60000 <= balance <= 75000)

 

 

* Page 297: The fifth line under listing 8.7 currently reads:

 

5000 >= balance >= 20000

 

The greater than or equals symbols should instead be smaller than or equals symbols:

 

5000 <= balance <= 20000

 

The second line down from the above line looks like:

 

balance >= 5000 && balance <= 20000 is logically equivalent to

 

This line should instead read:

 

balance >= 60000 && balance <= 75000 is logically equivalent to

 

 The next line currently looks like:

 

5000 >= balance >= 20000

 

which should be changed to

 

60000 <= balance <= 75000

 

 

* Page 338: The fourth point on the middle of the page looks like the following:

 

4. Determine if the loop should be terminated (line 26).

 

line 26 should be changed to line 25.

 

 

* Page 341: The headline above the last paragraph currently reads:

 

1. Each of the three loop parts in the for loop is optional, however the parenthesis after the for keyword must always contain three semicolons.

 

 

In the second line three semicolons should be changed to two semicolons.

 

 

* Page 392: Line 11 currently reads:

 

…MaxArray(person1Sales[0], person2Sales[0]…

 

MaxArray should be changed to MaxAmount and a parenthesis should be added at the end:

 

…MaxAmount(person1Sales[0], person2Sales[0])…

 

 

* Page 401: The third line from the bottom of the page contains the text:

 

because the initial value of areValueEqual is set to true (in line 27), it will remain true until

 

where (in line 27) should be changed to (in line 23)

 

 

* Page 409, Figure 10.15: The first line of code reads:

 

for (int i = 0; <elevators, Length; i==)

 

This line should be changed to:

 

for (int i = 0; i < elevators.Length; i++)

 

 

* Page 432, Listing 11.2: The second line from the bottom of the page reads:

 

// This block is repeated seven times

 

This line should instead be inserted in the outer for loop and the following line should be inserted in the inner for loop:

 

// This block is repeated 7 x 24 times

 

resulting in the following code:

 

...

ushort [ , ] requests = new ushort [7,24];

...

for (int i = 0; i < 7; i++)

{

    // This block is repeated seven times

    ...

    for (int j = 0; j < 24; j++)

    {

        // This block is repeated 7 x 24 times

        ...

        ... requests[i , j] ...

        ...

    }

...

}

...

 

 

* Page 451: The seventh line above the heading: Arrays of More Than Two Dimensions currently reads:

 

jagged array with 4 rows of base type double and declared as

 

In this line 4 should be exchanged with 3 to read:

 

jagged array with 3 rows of base type double and declared as

 

 

* Page 452, Figure 11.12: The arrow pointing at ushort [ , , ] is marked with the text:

 

two commas specifies two dimension

 

This should be changed to:

 

two commas specify three dimensions

 

 

* Page 455: The last line before Table 11.3 currently looks like:

 

Some of the examples in Figure 11.3 contain specific arrays that are described after the table:

 

Figure should be exchanged with Table:

 

Some of the examples in Table 11.3 contain specific arrays that are described after the table.

 

 

* Page 466: The second last line of the first paragraph after the Note currently reads:

 

testScores.Length (here 1000), and the value of testScores[testScores.Length] will

 

In this line - 1 needs to be added to the text inside the square brackets:

 

testScores.Length (here 1000), and the value of testScores[testScores.Length - 1] will

 

 

* Page 471: The second line under the Note reads:

 

3-24. The Main() utilizes its functionality to…

 

7 should replace 3 and the word method must be inserted after Main():

 

7-24. The Main() method utilizes its functionality to…

 

 

* Page 473: The first line reads:

 

The BinarySearch method (lines 3-24)…

 

3 should be exchanged with 7:

 

The BinarySearch method (lines 7-24)…

 

 

* Page 499: The second last line of the note (called: Calling a static Method) reads:

 

Rocket.Average(…), because the class name format clearly signals that we are calling a sta-

 

Rocket.Average(…) should be changed to rocketA.Average to form the following line:

 

rocketA.Average(…), because the class name format clearly signals that we are calling a sta-

 

 

* Page 539: The word Statistician appears in line 3 and line 6 in the first paragraph under the heading: Other Important Actions Performed at the Time of Object Creation. This word should be exchanged with the word:

BankStatistician

 

 

* Page 579: The third line of question 6.b currently reads:

 

Is the previous statement valid now? Why or why not?

 

This line should be changed to:

 

Is the previous statement in question a. valid now? Why or why not?

 

 

* Page 580: The line under the section called Programming Exercises commence with the text:

 

Exercises 2-5 each build…

 

This should instead be:

 

Exercises 2-4 each build…

 

 

* Page 584: The eighth line reads:

 

Instead of operator overloading, let us write the cleaner looking and more intuitive line

 

The second word: of   should be deleted:

 

Instead, operator overloading let us write the cleaner looking and more intuitive line

 

 

* Page 604: The second line of the last paragraph reads:

 

Listing 14.4. During its creation, tt allows us to specify the names of the regions for which we

 

tt should be exchanged with: BirthList’s instance constructor:

 

Listing 14.4. During its creation, BirthList’s instance constructor allows us to specify the names of the regions for which we

 

 

* Page 637: The second line in the section: Namespaces and Compilation Units looks like:

 

ElevatorSimulation (spanning lines 3-61 and containing the Elevator, Person and

 

61 should be exchanged with 50:

 

ElevatorSimulation (spanning lines 3-50 and containing the Elevator, Person and

 

 

The third line in the same section contains the text:

 

(in lines 63-101)

 

63 should be exchanged with 52:

 

(in lines 52-101)

 

 

* Page 645. The second line of the note box called: Do Not Over-Abbreviate the Alias Names, looks like:

 

For example, if, instead of the alias ElevatorBuilding specified in the following line of Figure 15.5

 

Figure 15.5 should instead be Figure 15.2

 

 

 

* Page 708: The second line of the last paragraph reads:

 

defined. The source code is nearly identical to Listing 16.2 of Chapter 16, but this time

 

Listing 16.2 should be changed to Listing 16.3.

 

 

* Page 757: Replace question 1 of the Review Questions with the following question:

 

1. Consider an Animal class from which the Dog, Cat, and Duck classes are derived. Suppose that any Animal can make a sound with a method called Sound and that you want to call different versions of this method polymorphically in the classes derived from Animal. Would you provide an implementation for this method in the Animal class or declare it abstract here? Why?

 

 

* Page 764: The lowermost curly brace in Figure 18.1 is currently marked:

 

myTime

 

The word Boxed should be added after myTime:

 

myTime Boxed

 

 

* Page 774: The line above the Note box currently reads:

 

at MyClass.Main() in C:\Temp\TempC#Programs\UncaughtException.cs:line 19

 

19 should be changed to 9

 

 

* Page 782: The last line looks like:

 

(pretends to) close the files are positioned in finally blocks (lines 46-49 and lines 54-57).

 

Lines 54-57 should be changed to Lines 64-67

 

 

* Page 821. The third line from the bottom of the page currently looks like:

 

csc /doc: RacingCar.xml RacingCar.cs

 

The space between doc: and RacingCar.xml should be removed so the text instead looks like the following line:

 

csc /doc:RacingCar.xml RacingCar.cs

 

 

* Page 829: The third line in question 2 looks like:

 

#define

 

TEST should be added to this line:

 

#define TEST

 

 

* Page 863: The fourth line from the bottom of the page reads:

 

line 24 or line 26. If key is less than the middle element (checked in line 21), the key value for

 

line 21 inside the parentheses should be changed to line 23

 

line 24 or line 26. If key is less than the middle element (checked in line 23), the key value for

 

 

* Page 877: The answer to programming exercise number 7 in Chapter 5 is not included in the book. However it is part of the answer (the source code) provided on the web site (www.samspublishing.com) for downloading.

 

 

* Page 890: Answer 5.c currently reads:

 

c. ((number % 2 == 0) || (weight < 100))

 

This should be changed to:

 

c. (((number % 2 == 0) && (weight < 100)) || (weight < 100))

 

 

* Page 906: Question 6.e should be No instead of Yes.

 

 

* Page 906: Question 8.b should have the following text added after Valid.

 

myArgument = 100 and yourArgument = 200

 

to form:

 

b. Valid.  myArgument = 100 and yourArgument = 200

 

 

* Page 927: The answer to question 1 of Chapter 17’s review question should look like the following instead of what is currently shown on the page:

 

1. The Sound method in the Animal class should be abstract, because we don’t know the sound an Animal makes (it could be meow, vroof, or something else).

 

 

* Page 945: The second line of answer 6 currently reads:

 

csc /doc: <XML_FileName>.xml <FileName>.cs

 

The space between doc: and <XML_FileName> should be removed:

 

csc /doc:<XML_FileName>.xml <FileName>.cs