Head First C#

Errata for Head First C#

Submit your own errata for this product.


The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color Key: Serious Technical Mistake Minor Technical Mistake Language or formatting error Typo Question Note Update



Version Location Description Submitted By Date Submitted Date Corrected
Printed, PDF, ePub, Mobi, Safari Books Online, Other Digital Version
Page Lab #2 (469-480)
Various locations

469 - in the left-hand annotation, the text "send the three weapon icons" is changed to "send the weapon and potion icons", and "player icons" is changed to "player icon" 476 - the fourth annotation is changed to: "The playerís constructor sets its HitPoints to 10 after the base constructor is called." 480 - missing semicolon in Weapon constructor (PickedUp = false;) 482 - the text "the potionís Used() method" is changed to "the potionís Used property"

Andrew Stellman
Andrew Stellman
O'Reilly AuthorO'Reilly Blogger 
Oct 13, 2013  Oct 18, 2013
Printed, PDF
Page Various (1st printing)
Various typos

This is a catch-all for typos fixed in the Oct 2013 printing 722 -- "Modify" is misspelled "Modfiy" 759 -- The comma should be removed after "then the latest C# code" 760 -- Removed "Why," from 1st column, last para, 1st line

Andrew Stellman
Andrew Stellman
O'Reilly AuthorO'Reilly Blogger 
Oct 13, 2013  Oct 18, 2013
PDF
Page WPF PDF
Multiple locations

Several changes made to the WPF PDF posted on the book's website. Page 500: In the header, change "a Windows Store app page" to a "a WPF application" The body text should be: The Go Fish! game that you built in Chapter 8 would make a great WPF application. Open Visual Studio and create a new WPF Application project (just like you did for Save the Humans). Over the next few pages, youíll redesign it in XAML, with a main window that adjusts its content as it's resized. Instead of using Windows Forms controls on a form, youíll use WPF XAML controls. Page 528: In the header, change "Windows Store app" to "WPF application" Page 532: In the box that starts "Every program you've written...", change "Windows Store app" to "WPF application" Page 680: In the first line, change "In Chapter 14, we built" to "When you read through Chapter 14 in the book, you saw that we built" And in the second paragraph of step 1, change "from the Windows Store app" to "from the Windows Store app we showed you in the book (you can download them from the book's website)" Pages 726-727: Fixed diagram of object model and first line of code to reflect WPF instead of Windows Store. Page 750: In the first line, change "Create a new Windows Store app" to "Create a new WPF application"

Andrew Stellman
Andrew Stellman
O'Reilly AuthorO'Reilly Blogger 
Jul 09, 2014 
Printed, PDF
Page 44
Top of page, first paragraph

At the end of the first paragraph, you are told to use IntelliSense to fill in enemyPointer.PointerEntered from the list. This should be enemy.PointerEntered instead of enemyPointer.PointerEntered.

Note from the Author or Editor:
The text has been fixed to reflect this change.

Jeff Shininger  Sep 21, 2013  Oct 18, 2013
PDF
Page 131
Step 3

Step 3 says "The labels on the righthand side of the form" but the illustration of the form shows the labels on the lefthand side.

Peter Smith  Jan 03, 2014 
Printed
Page 178
Code Listing, last line

Last line of code says Accuracy = 100 * Correct / (Missed + Correct); The same function updates the field Total, so why not use it here and let the code be: Accuracy = 100 * Correct / Total;

Note from the Author or Editor:
You're right! Nice catch.

Anonymous  Nov 16, 2013 
Printed
Page 202
bottom right image

Sample form has two checkboxes: Fancy Decorations Healthy Decorations Second box should be Healthy Option to match the image on p 200 upper left and 206-207 images.

Gary Ray  Oct 08, 2013  Oct 18, 2013
Printed, PDF, ePub
Page 225
Step #3 at the bottom of the page

The following line of code was accidentally deleted from the page after the first line of text in step #3: public int BagsOfFeed { get; private set; } It needs to be added back. Also, the following caption box was missing: A property is read-only if it canít be set by another class. You can make its set accessor private. You can also leave out the set accessor for normal properties, but not automatic properties (which must have both get and set accessors).

Andrew Stellman
Andrew Stellman
O'Reilly AuthorO'Reilly Blogger 
Sep 10, 2013  Oct 18, 2013
Printed, PDF
Page 334
Step 7, bottom of page

The first star in step 7 refers to the read-only property Hot, yet both the initial Outside class description on page 332 and the solution on page 337 only refer to hot as a private field.

Note from the Author or Editor:
The text in step 7 has been fixed.

Jeff Shininger  Sep 22, 2013  Oct 18, 2013
Printed, PDF
Page 397
Bottom of page

In the title of the grey informational block at the bottom of the page, "Environment" is spelled "Envrionment".

Jeff Shininger  Oct 06, 2013  Oct 18, 2013
Printed, PDF, ePub
Page 504 to 507
Text and caption changes

p504, first paragraph: "The second column has a fixed width of 20 pixels" -- should be "40 pixels" p504, table: In the top two cells of the rightmost column, Grid.Column= "1" should be Grid.Column= "2" p506, captions: Changed "20-pixel" and "5-pixel" to "20x20-pixel" and "5x5-pixel" p507, top-right paragraph: "Five of these device-independent units combine..." -- should be "A five-by-five square of these...", and a similar change for "four" (should be "four-by-four")

Andrew Stellman
Andrew Stellman
O'Reilly AuthorO'Reilly Blogger 
Sep 12, 2013  Oct 18, 2013
PDF
Page 509
1st grid on right side

CombiboxItem Should be: ComboboxItem This typo appears twice.

Anonymous  Sep 13, 2013  Oct 18, 2013
Printed, PDF
Page 542
The XAML in step 1

The third RowDefinition should be deleted because no controls are added to it.

Anonymous  Sep 18, 2013  Oct 18, 2013
PDF
Page 554
1st line of the ReadGuyAsync method

Instead of this: if (String.IsNullOrEmpty(Path)) It would be preferable to do this: if (String.IsNullOrWhiteSpace(Path))

Note from the Author or Editor:
Good point. I added a box to the bottom of the page teaching about IsNullOrWhitespace().

Anonymous  Sep 21, 2013  Oct 18, 2013
Printed, PDF
Page 565
Descriptions for ExcuseManager.ReadExcuseAsync() and ExcuseManager.WriteExcuseAsync()

I think the descriptions for ExcuseManager.ReadExcuseAsync() and ExcuseManager.WriteExcuseAsync() are reversed. The read method talks about serializing and the write method talks about deserializing.

Jeff Shininger  Nov 04, 2013 
Printed, PDF
Page 598
Screenshot of the MessageBox at the bottom of the page

The screenshot of the MessageBox at the bottom of the page should have a title bar that says "Warning: Resetting Hive" according to the code.

Jeff Shininger  Nov 20, 2013 
PDF
Page 662
The ComicQueryManager class

In ComicQueryManage.cs, this line: CurrentQueryResults.Clear(); Should be removed from these methods: - LinqMakesQueriesEasy (page 662) - ExpensiveComics (page 662) - LinqIsVersatile1 (page 669) - LinqIsVersatile2 (page 669) Calling CurrentQueryResults.Clear() is redundant because a new instance of CurrentQueryResults is being created in the class's constructor. It might be better to add a note that explains what the Clear() method does and why it's not necessary in this case.

Note from the Author or Editor:
Agreed. I made the change, and added a box that helps explain what's going on: The CurrentQueryResults property is used to display the query results with data binding. It doesnít need to be cleared because a new page object is created each time page navigation occurs, and it has its own new instance of ComicQueryManager, with a newly created empty collection.

Anonymous  Sep 24, 2013  Oct 18, 2013
Printed, PDF
Page 675
Pool Puzzle solution

The Pool Puzzle solution has blanks being filled in with "words" and "inner", yet neither snippet exists in the pool.

Note from the Author or Editor:
An entire column of words (Value Key Words words this inner) seems to have been deleted from that pool puzzle. I'll put it back.

Jeff Shininger  Dec 15, 2013 
Printed, PDF
Page 679
Step 2

Step 2 refers to a Purchases class. This should be the Purchase class.

Jeff Shininger  Dec 15, 2013 
PDF
Page 683
The CombineJimmysValuesIntoGroups() method

This: foreach (var price in group) message += price.ToString() + " "; Should really be: foreach (var issue in group) message += issue.ToString() + " "; Because 'group' contains a sequence of Comic.Issue numbers.

Note from the Author or Editor:
I agree!

Anonymous  Sep 24, 2013  Oct 18, 2013
Printed, PDF
Page 698
Line #16 in the code block

There's a copy-paste error on line #16 of the code, where the text ", Target" was accidentally pasted into the code. The correct line should be: <TextBlock Text="{Binding Comic.Issue}" This affects only the first run of books delivered to retailers, and has been fixed for all subsequent printings.

Andrew Stellman
Andrew Stellman
O'Reilly AuthorO'Reilly Blogger 
Aug 16, 2013  Oct 18, 2013
PDF
Page 698
First line of XAML after the 2nd paragraph

In this line of XAML: <Grid Height="780" Width="600" Grid.Row="2" Grid.ColumnSpan="2" Margin="0,20,0,0"> The Width attribute should be removed because, if you view the app at a resolution higher than 1366 x 768, the row containing this Grid will no longer be aligned with the row above it (it will be pushed to the right side of the screen). There are probably other ways to solve this. Also, the Height attribute appears to be unnecessary.

Note from the Author or Editor:
Good point. The Height and Width tags are from the grid earlier in the chapter, so I think it's easier for readers to understand if they're left in. Adding this annotation: If you view the app at a high screen resolution, is the Grid no longer aligned with the row above it? If so, try deleting its Width attribute.

Anonymous  Sep 25, 2013  Oct 18, 2013
Printed, PDF, ePub
Page 730-732
Various

p730: fixed typo in bottom right hand-written annotation where the property name AmysSecretIngredientMethod() was mistyped as GetSecretIngredient() p732: fixed typos where property names MySecretIngredientMethod() and AmysSecretIngredientMethod() were mistyped as GetSecretIngredient() p732: fixed typo where SuzannesSecretIngredient() method was mistyped as SuzannesIngredientList() p733: changed wording step 5 so it refers to message boxes and not console output

Andrew Stellman
Andrew Stellman
O'Reilly AuthorO'Reilly Blogger 
Oct 07, 2013  Oct 18, 2013
PDF
Page 742
The MainPage() method

The SettingsPane.GetForCurrentView().CommandsRequested event is being subscribed to in the constructor of MainPage. This results in a duplicate "About" command being added to the Settings pane every time the app returns from another page. I'm not sure of the best way to fix this, but in this case you could add a line of code at the beginning of the CommandsRequested event handler which checks to see if at least one command has already been added to the settings pane: void MainPage_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args) { if (args.Request.ApplicationCommands.Count > 0) return; .... ]

Note from the Author or Editor:
Nice catch! I decided to use a static field because it's easier for the reader to understand. I also added an annotation telling the reader to try removing the line that sets the field to true, so they can see the multiple commands added to the Settings charm. static bool aboutCommandAdded = false; public MainPage() { this.InitializeComponent(); if (!aboutCommandAdded) { SettingsPane.GetForCurrentView().CommandsRequested += MainPage_CommandsRequested; aboutCommandAdded = true; } }

Anonymous  Sep 30, 2013  Oct 18, 2013
Printed, PDF
Page 743
The list of Windows Key shortcuts at the top of the page

This: Bring up the charms with [Windows Key] + I Should be: Bring up the charms with [Windows Key] + C

Anonymous  Sep 30, 2013  Oct 18, 2013
PDF
Page 748
The first Roster class diagram

This: Players: IEnumerable<string> Should be: Players: IEnumerable<Player> because the LINQ query to the right of the diagram references the 'player.Starter' property.

Anonymous  Oct 08, 2013  Oct 18, 2013
Printed, PDF, ePub
Page 755
LeagueViewModel class diagram

In the methods section of the LeagueViewModel class diagram, both occurrences of Model.Roster should be replaced with IEnumerable<Player>.

Andrew Stellman
Andrew Stellman
O'Reilly AuthorO'Reilly Blogger 
Oct 09, 2013  Oct 18, 2013
PDF
Page 757
The RosterViewModel class

In this project, it's not necessary for the RosterViewModel class to implement INotifyPropertyChanged. The app will not run any differently if you remove the OnPropertyChanged() method and remove the reference to that method in the TeamName setter. Also, in the UpdateRosters() method it's not necessary to call Starters.Clear() or Bench.Clear().

Note from the Author or Editor:
You're absolutely right. I also added the following box to the bottom of the page: In a typical MVVM app, only classes in the ViewModel implement INotifyPropertyChanged. That's because the ViewModel contains the only objects that XAML controls are bound to. In this project, however, we didn't need to implement INotifyPropertyChanged because the bound properties are updated in the constructor. If you wanted to modify the project to let the Brian and Jimmy change their team names, you'd need to fire a PropertyChanged event in the TeamName set accessor.

Anonymous  Oct 08, 2013  Oct 18, 2013
PDF
Page 759
2nd column, 1st answer

The third paragraph references <UserControl.ContentTemplate>, but the UserControl class in WinRT doesn't have a ContentTemplate property.

Note from the Author or Editor:
You're correct. I removed that question and answer.

Anonymous  Oct 09, 2013  Oct 18, 2013
PDF
Page 780
XAML in top half of the page

The XAML shown for the "Pressed" visual state is actually the XAML for the "PointerOver" visual state.

Anonymous  Oct 13, 2013  Oct 18, 2013
PDF
Page 781
Step 1, 2nd handwritten note

This: Minutes and seconds range from 0 to 60 Should be: Minutes and seconds range from 0 to 59

Anonymous  Oct 13, 2013  Oct 18, 2013
Printed, PDF
Page 781
Step 2

Removed an unnecessary style from the <UserControl.Resources> section (<Style TargetType="TextBlock"> ... </Style>)

Andrew Stellman
Andrew Stellman
O'Reilly AuthorO'Reilly Blogger 
Oct 13, 2013  Oct 18, 2013
Printed, PDF
Page 790-791
Notes on bottom of 790, "handwritten" on right side of 791

On pages 790 and 791, a couple of notes (bottom of 790, "handwritten" on right side of 791) refer to the CreateFrameImages() method. I believe this is supposed to be referring to the StartAnimation() method.

Jeff Shininger  Dec 28, 2013 
Printed, PDF
Page 791
Callout on right side of page

"The Storyboard is garbage collected after the animation completes. You can see this for yourself...after the animation ends." As written, the animation never actually ends because its Duration is set to RepeatBehavior.Forever. To make the animation end, you could change this line: animation.RepeatBehavior = RepeatBehavior.Forever; To something like this: // repeat animation twice animation.RepeatBehavior = new RepeatBehavior(2);

Note from the Author or Editor:
Good point. I added the following text to the box on that page: "--but first change its RepeatBehavior to new RepeatBehavior(2) or the it will repeat forever and never end!"

Anonymous  Oct 14, 2013 
Printed, PDF
Page 801
Comment for the BeeMovedHandler method

On page 801 in the comment for the BeeMovedHandler method, it says "the BeeViewModel fires its BeeMoved event", though I think this is supposed to say " BeeStarModel fires its BeeMoved event", as this event is fired from the Model, not the ViewModel.

Jeff Shininger  Dec 29, 2013 
PDF
Page 802
The CreateBees() method

This: int beeCount = _random.Next(5, 10); Should be: int beeCount = _random.Next(5, 16); Because the instructions on page 800 specify between 5 and 15 bees. In the Next() method, the first parameter is inclusive but the second parameter is exclusive, so to get 15 bees you have to pass in 16. In that same method, this: int s = _random.Next(50, 100); Should be: int s = _random.Next(40, 151); Because the directions on page 800 specify a size between 40 and 150. There's a similar error on page 803, in the CreateStars() method: int starCount = _random.Next(5, 10); Should be: int starCount = _random.Next(5, 11);

Anonymous  Oct 16, 2013 
PDF
Page 803
The MoveOneBee() method

This: int beeCount = _stars.Count; Should be deleted because it's not used and, if it was, it should be: int beeCount = _bees.Count;

Anonymous  Oct 16, 2013 
Printed, PDF
Page 813
-

On page 813, the Shot class has a private _direction field and a Direction property that you would assume serves to access the backing field, yet it has a standard get accessor that doesn't access the private field. The get accessor should either return _direction, or the private field should be gotten rid of and all occurrences replaced with the Direction property. The latter option is what is in the solution code.

Jeff Shininger  Dec 31, 2013 
Printed, PDF
Page 818
Last set of instructions

The last set of instructions refers to the ItemsPath for the ItemsControl. This should be the ItemsSource for the ItemsControl.

Jeff Shininger  Jan 02, 2014 
Printed, PDF
Page 820
-

On page 820, don't we need to include the namespace Windows.UI.Core to use the KeyEventArgs class for our event handlers?

Note from the Author or Editor:
Yes, you do! Good catch.

Jeff Shininger  Jan 02, 2014 
PDF
Page 836 - 837
The BeeAttackModel class

The value of the _beeWidth field is assigned in the StartGame() method, but it's never used. It should be used, though, in the BeeLanded() method: if ((beeLeft < _flowerLeft) || (beeLeft > _flowerLeft + _flowerWidth)) Should be: if ((beeLeft + _beeWidth) < _flowerLeft || beeLeft > (_flowerLeft + _flowerWidth)) ...because a bee will always be counted as missed if the bee's left edge is even one pixel less than the flower's left edge.

Anonymous  Oct 24, 2013 
PDF
Page 837
The NextHiveLocation() method

In this line: double delta = 10 + Math.Max(1, Score * .5); Math.Max() is superfluous because Score is an int that's initialized to zero and it's incremented by 1 each time the score is increased. Instead, you could just write: double delta = 11 + (Score * .5); // parentheses are optional Also in the NextHiveLocation() method, in this line: _lastHiveLocation += delta * (_random.Next(2) == 0 ? 1 : -1); The multiplication operation could be removed: _lastHiveLocation += (_random.Next(2) == 0) ? delta : -delta;

Anonymous  Oct 24, 2013 
PDF
Page 839
The StartFlapping() method

" currentInteval" is a misspelling of " currentInterval"

Anonymous  Oct 24, 2013 
PDF
Page 840
The BeeAttackViewModel class

These properties: private Size _playAreaSize { get; set; } private Size _hiveSize { get; set; } private Size _flowerSize { get; set; } Should be declared as fields. Unless a property contains code (i.e., it's not an automatic property), I don't think there's any reason to create a private property.

Anonymous  Oct 24, 2013 
PDF
Page 849
The ReceiveCash() method

There are duplicate, nested checks for the value of the 'amount' parameter. As written, the line inside the 'if' statement that calls Console.WriteLine will never be reached. The ReceiveCash() method should probably be: public int ReceiveCash(int amount) { if (amount > 0) { Cash += amount; return amount; } Console.WriteLine("{0} says: {1} is not an amount I'll take", Name, amount); return 0; } This error is also in the second edition of the book.

Anonymous  Oct 26, 2013 
PDF
Page 862
First "handwritten" sentence on the page

This: Again, weíre using the same Guy class from leftover #1. Should be: Again, weíre using the same Guy class from leftover #2.

Anonymous  Sep 09, 2013  Oct 18, 2013
PDF
Page 866
Code for the SportCollection class

This: int maxEnumValue = Enum.GetValues(typeof(Sport)).Length - 1; Should be: int maxEnumValue = Enum.GetValues(typeof(Sport)).Length; because subtracting one from maxEnumValue prevents the loop from reaching the last item in the Sport enum (that last item is Fencing).

Anonymous  Oct 28, 2013 
PDF
Page 866
2nd paragraph

This: "...it automatically adds the MoveNext() and Current methods." Should be: "...it automatically adds the MoveNext() method and the Current property." The word "the" appears twice in a row in the third sentence: "When it executes, the the first yield..." This one could be due to my lack of understanding, but it looks like there's something missing in this sentence: "Its MoveNext() method returns false if the enumerator method returns." Should it instead be something like: "Its MoveNext() method returns false when the enumerator is positioned after the last element in the collection."

Anonymous  Oct 28, 2013 
Printed, PDF, ePub, Mobi, Safari Books Online, Other Digital Version
Page 866
Top code block

Yield return example misses the last sport. Need to fix this line of code to change < to <= : for (int i = 0; i <= maxEnumValue; i++) {

Andrew Stellman
Andrew Stellman
O'Reilly AuthorO'Reilly Blogger 
Dec 27, 2013 
PDF
Page 867
The indexer for the GuyCollection class

In this line: throw new IndexOutOfRangeException("Name " + name + " was not found"); It might be more suitable to throw a KeyNotFoundException instead of an IndexOutOfRangeException.

Anonymous  Oct 28, 2013