Head First C# by Andrew Stellman, Jennifer Greene This errata page lists errors fixed in the January 2008 reprinting. If you have technical questions or error reports, you can send them to booktech@oreilly.com. Please specify the printing date of your copy. This page was updated March 5, 2008. Here's a key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification Confirmed errors: (ix) Table of Contents (Summary), chapter 8; "enums" s/b "Enums" (ix) Table of Contents (Summary), chapter 11; "events" s/b "Events" (ix) Table of Contents (Summary); TOC summary ends with Lab 3. Doesn't include "appendix i: leftovers", starting on page 703. (x) Table of Contents, entry for page 5; "startbuilding" s/b "start building" (xv) 1st paragraph, last sentence.; "You'll make your object's data private, add methods to protect how that data is accessed." s/b "You'll make your object's data private, and add methods to protect how that data is accessed." (xxii, 483) 1st paragraph, 5th line.; "subscibe" s/b "subscribe" (xxviii) fifth TOC item This should be "#5 Windows Presentation Framework" -- it's missing the # at the beginning. (xxxvi) "Setting up Visual Studio 2008 Express Edition", 3rd bullet point, 2nd line; Missing period. "installation That should" s/b "installation. That should" (xxxvi) Screenshot on page replaced in reprint with an image that shows how the installer looks now that the final version of Visual Studio Express is out ( vs08setup.png). Even though the picture looks different all of the text stays the same. (xxxviii) 2nd line from the bottom of the page; "execises" s/b "exercises" (9) - top left annotation ("The toolbar has buttons...") This is supposed to be a filled-in answer. There should be dotted-line blanks under it. (10) remove the top right annotation "We've blown up..." (11) first question, last two lines Change "writes the action code, or the code that does the work" to "writes the code that actually does the work" {11} fifth question and answer This entire question and answer should be changed. Here's the new Q and A: Q: Can I change the names of the files the IDE generates for me? A: Absolutely. When you create a new project, the IDE gives you a default form called Form1 (which has files called Form1.cs, Form1.Designer.cs and Form1.resx). But you can use the Solution Explorer to change the names of the files to whatever you want. By default, the names of the files are the same as the name of the form. If you change the names of the files, you'll be able to see in the Properties window that form will still be called Form1. You can change the name of the form by changing the "(Name)" line in the Properties window. If you do, the filenames won't change. C# doesn't care what names you choose for your files or your forms (or any other part of the program). But if you choose good names, it makes your programs easier to work with. For now, don't worry about names -- we'll talk a lot more about how to choose good names for parts of your program later on. (13) step #2 Add an annotation pointing to the paragraph for #2 that says: You can also use the "Properties" window in the IDE to set the Size property. The little black arrow is just there to make it easy to access the most common properties of any control. (13) In the text under step #3, change this text: "Click Import, find your logo, and you're all set:" to this: You'll see a Select Resource window pop up. Click the "Local Resource" radio button to enable the "Import..." button at the top of the form. Click that button, find your logo, and you're all set: Add a new annotation to this page underneath the middle one that starts 'Choose "Zoom"' with an arrow pointing up at that annotation. It should say: Then click "Choose Image" to bring up the Select Resource dialog box so you can import a local resource. (14) Change the text in the middle annotation from this: If you click on Form1.resx in the Solution Explorer, you can see the logo that you imported. to this: Go to the Solution Explorer and click on the plus icon next to Form1.cs to expand it (if it's not already expanded). This will display two files: Form1.Designer.cs and Form1.resx. Double-click on Form1.resx, click on the arrow next to "Strings", and select "Images" from the drop-down list (or hit Ctrl-2) to see the logo that you imported. Add an annotation pointing to the third screenshot on the page that's displaying pictureBox1.Image. The annotation should read: If you chose the other "Import..." button from the Select Resource dialog on the last page, then your image will show up in the Resources folder in the Solution Explorer instead. Don't worry -- just go back to Select Resources, choose "Local Resource", and re-import the image into the resources and it'll show up here. (18) Insert a new #2 bullet between the picture and the current #2 bullet that says: Click on the Add button in the Add New Item window. (19) Bottom-Left paragraph; "queries that you are stored" should be "queries that are stored" (21) Add an annotation that points to the IsIdentity line in the screenshot on this page that says "You'll need to click on the right column and select Yes from the drop down next to IsIdentity to designate ContactID as your record Identifier." (22) First paragraph; Instead of saying "you're going to track", the book says "your going to track" (22) Laverne Smith's email address is missing a period. It should be laverne.smith@xyzindustries.com (26) top left corner Add a note in the blank space in the top-left corner of the page: In very rare cases, a few people sometimes have problems getting the SQL database to work. If you run into any trouble, don't worry -- go to the Head First C# forum at http://headfirstlabs.com/hfcsharp/ for help troubleshooting the problem. {26} Screenshot below step 2: Title bar of dialog should say "Microsoft Visual C# 2008 Express Edition" (not "...2005 Express Edition"). Image is otherwise fine as is. (29) Add an annotation pointing to one of the cards: Objectville Paper Company is in the United States, so the CEO writes dates so that 05/26/07 means May 26, 2007. If your machine is set to a different location, you may need to enter dates differently -- you might need to use 26/05/07 instead. (29) Top Left Card; Phone number[(212)555-81125] has too many numbers in it. It should be (212)555-8125. (29) Top Left Card and Middle Card; Both emails are missing the "." between xyzindustries and com {31} In diagram, the file extension ".xsd" is missing from the end of the XML file, which should be labeled ContactDBDataSet.xsd. (32) step 2, change the last sentence ("If you don't see the columns...") to this: Click the plus sign next to the People table to expand it -- you'll see the columns that you added to your table. When you click on the People table in the Data Sources window and drag it onto your form, the IDE automatically adds data controls to your form that the user can use to browse and enter data. By default it adds a DataGridView, which lets the user work with the data using one big spreadsheet-like control. Click the arrow next to the People table and select Details -- that tells the IDE to add individual controls to your form for each column in the table. (32), an annotation that says: "This is the little arrow you should click on." Change it to say this: "Click this arrow and choose 'Details' to tell the IDE to add individual controls to your form rather than one large spreadsheet-like data control." (32) In the bottom annotation, change "fields" to "columns". (36) Add a "Watch It!" to this page: Every time you build your program, the IDE puts a fresh copy of the database in the bin folder. This will overwrite any data you added when you ran the program. When you debug your program, the IDE rebuilds it if the code has changed -- which means that your database will sometimes get overwritten when you run your program in the IDE. If you run the program directly from the bin/debug or bin/release folder, or if use the installer to install it on your machine, then you won't see this problem. (39) bottom right-hand annotation Add this sentence to the annotation: "They're part of ContactDB.mdf database file, which gets installed along with your program." {45} In the code at the very bottom of the page, change: this.Text = "Contacts"; to this.Text = "Objectville Paper Company contact list"; (49) top annotation, fourth line change "select it" to "tell the IDE to fill it in for you" {51} bottom annotation, sixth line Change: the designer tab to: the tab labeled "Form1.cs [Design]" (52) third annotation The underline isn't lined up with the words "inside a class" (52) bottom annotation Add another annotation underneath this one pointing up at it that says: "You'll see slightly different using lines if you're using Visual Studio 2005" (56) Top paragraph, second sentence Change "Let's remove the Main method" to "Open up the program you wrote in Chapter 1 and remove the Main method" (57) First paragraph, second line Change "messagebox" to "MessageBox" (63) Dictionary definition Put a period after "adapted" and capitalize "The" in "The drill's" {65} Change the loop in the middle of the page to for (int i = 0; i < 8; i = i + 2) {69} code at top of page should be if ((someValue == 3) && (name.Equals("Joe"))) (69) annotation that starts "The second part" Add a sentence to the end of the annotation: The test is run before the code block, and the block is executed only if the test is true. (69) annotation that starts with "This is where the loop" Add a sentence to the end of the annotation: This is called the iterator, and it's run immediately after all of the statements in the code block. (make the color of "immediately after" black and underline it) (71) lower left-hand corner Add an annotation pointing up at the Sharpen that says: "Remember, a for loop always runs the conditional test at the beginning of the block, and the iterator at the end of the block" (76) in step #2, change this text: "from 0 to 254" to this: "from 0 to 253" (79) add an annotation pointing to the second for line in the code: We used "&& Visible" instead of "&& Visible == true". It's just like saying "if it's visible" instead of "if it's true that it's visible" -- they mean the same thing. (79) bottom paragraph, third line, boldfaced courier text Change "&& Visible == true" to "&& Visible" (93) Under "Check it out for yourself!" "Open any project that uses a button called button1, and use the IDE to search the entire project for the text "new button1". should read "Open any project that uses a button called button1, and use the IDE to search the entire project for the text "button1 = new". (94-96) semicolon missing after "Navigator navigator1 = new Navigator()" in the second line of code under step 2 on page 94, fourth line of code on page 95, fourth line of code on page 96 {97} Third paragraph, third line Change "Talker()" to "Talker" -- remove the parentheses {98} top annotation Change "is a special kind of field" to "is very similar to a field" {102} top left annotation, fifth line Change "T()" to "T" -- remove the parentheses {108} Class diagram in the upper right-hand corner; "ClassMaker" should be changed to "CandyMaker" -- it's currently the wrong solution to the problem. (110) top annotation, third line: change "lives" to "live" (112) step 1 In the title line, change "six labels" to "three labels" In the first line of the paragraph, change "The labels on the right-hand side of the form" to "The top two labels". In the second line of the paragraph, change "the third label on the right" to "the third label" In the last line, change "label4 and label5" to "label1 and label2" {114} first question, first, fourth and eighth lines: change "bob variable" to "bob field" (125) add an annotation pointing to the "decimal" bullet at the top of the page: When your program needs to deal with currency, you usually want to use a decimal to store the number. {125} third section, first three sentences that start "Did you notice how the byte type..." This is inaccurate, and we need to replace the first three sentences with: Sometimes you need to store a single character like Q or 7 or $, and when you do you'll use the char type. (make sure "char" is in courier) Also, add this sentence to the end of that paragraph: You write an escape sequence in your C# code using to characters, but your program stores each escape sequence as a single character in memory. (131) Last [normal] paragraph: "Now try passing it a boolean, but assigning the return value to a long" should change to: "Now try passing it a boolean but assigning the return value to a string." (133 and 134), instructions - replace "odometer" with "mileage reading from the car's odometer" {137} headline Change "Objects are variables, too" to "Objects use variables, too" {141} Crossword puzzle, 3 Down There is no mention of camel case prior to page 141. The index shows camel case first being introduced on page 201. (145) Change the last annotation to: "The WhoAmI() method should pop up this message box. Make sure the message includes the ear size and the title bar includes the name." {145 and 146} instructions Change "Make two elephant instances and then have them switch properties" to "Make to elephant instances and then swap the reference variables that point to them" {147} Step 2; lloyd = Lucinda; should be: lloyd = lucinda; {149} tool tip box, third line Change "field" to "property" {152} step 1, second and third sentences Change "method" to "parameter" (154) first answer, sixth line Change "(non-static) a" to "a (non-static)" (154) bullet points, right-hand column, third bullet Add a colon after "labels" -- "References are like labels:" {166} class diagram and code for Greyhound Change "MyRandom" to "Randomizer" in two places -- it's in the class diagram and in the sixth line of the code next to it Add an annotation (there should be room underneath the line of code) that says: You only need one instance of Random -- each Greyhound's Randomizer reference should point to the same Random object. (170) Add an annotation pointing to the screenshot that says: Make sure you set each PictureBox's SizeMode property to Zoom {176} class diagram Remove "HealthyOption" from the class diagram (183) top - "The Problem Up Close" the "Close" is cut off {190} change this line of code: return cookieRecipe + " " + secretIngredient; to this: return cookieRecipe + " and the secret ingredient is " + secretIngredient; {190} - in # 3. int loyalCustomerAmount = 94: change 94 to 54 {190} in #5. mySuperChef.cookieRecipe = "get 3 eggs..." Make the "g" uppercase -- "Get 3 eggs..." (190) - add an annotation at the bottom of the page pointing to the answer to #7: Even though you created a local variable called loyalCustomerAmount and set it to 54, that didn't change the object's loyalCustomerAmount value, which is still 60 -- so it won't print the secret ingredient. {193} - bottom block of code Add this line of code above "public int GetNumberOfCows()": public const int FeedMultiplier = 30; with this annotation pointing to it: "The farmer needs 30 bags of feed for each cow." (195) change "Add a button the form that executes this statement." to: "Add a button to the form that executes this statement." (196) step #1 Add an annotation pointing to the second line of code ("public int FeedMultiplier"): This automatic property acts just like an int field. It has a public get, which means any other class can read the value of FeedMultiplier. But since its set is private, that makes it read-only -- it can only be set by an instance of Farmer. (197-198) Here's a list of the things that need to change on pages 197 and 198: --- p197- In the body text on the top of p197, in the fourth line change this: very first thing that gets run when the class is created to this very first thing that gets run when the class is instantiated add a comma after private ("...fields that need to be initialized are private, then an object initializer...") In Step 1: Change the last sentence of the paragraph for step 1 from: "Then weÕll set the two properties." to "We'll change feedMultiplier from a const to an int. We'll need a value for it, so let's make sure it gets passed into the constructor. We'll use the constructor to set the number of cows, too." Right underneath that, change the code from this: public Farmer(int numberOfCows, int feedMultiplier) { FeedMultiplier = feedMultiplier; this.NumberOfCows = numberOfCows; } to this: private int feedMultiplier; public Farmer(int numberOfCows, int feedMultiplier) { this.feedMultiplier = feedMultiplier; NumberOfCows = numberOfCows; } In the second annotation in the left margin of p197, change "new()" to "new" and put it in Courier. Add two annotations to p197 pointing to the code "private int feedMultiplier;": * We'll change feedMultiplier from a const to an int field. * Since we changed FeedMultiplier from a public const to a private int field, we changed its name so its starts with a lowercase f. That's a pretty standard naming convention you'll see throughout the book. Also, in the annotation pointing to "NumberOfCows", remove "this." from "this.NumberOfCows" -- it should just be "NumberOfCows". p198 - the "Way Up Close" box at the top of the page Make sure the code in this box matches the code on page 197: private int feedMultiplier; public Farmer(int numberOfCows, int feedMultiplier) { this.feedMultiplier = feedMultiplier; NumberOfCows = numberOfCows; } In this annotation: We need to set the feed multiplier first, because the second statement calls the NumberOfCows set accessor, which needs FeedMultiplier to have a value in order to set BagsOfFeed. change "FeedMultiplier" to "feedMultiplier" (with a lowercase f) In this annotation: YouÕll often see the this keyword a constructor. By calling this.NumberOfCows, weÕre telling C# to set the NumberOfCows property using its public set accessor. Make sure it points to "this." in the "this.feedMultiplier = feedMultiplier;" line in the code. Then change the annotation to say this instead: We need a way to differentiate the field called feedMultiplier from the parameter with the same name. That's where the "this." keyword comes in really handy. Change this annotation: If you leave off Òthis.Ó then C# will call the private set accessor instead. Give it a shotÑremove Òthis.Ó and see for yourself. to this: Since "this" is always a reference to the current object, this.feedMultiplier refers to the field. If you leave "this" off, then feedMultiplier refers to the parameter. So the first line in the constructor sets the private feedMultiplier field equal to the second parameter of the constructor. Also in the last paragraph of the No Dumb Questions answer, change: The InitializeComponent() method is called inside the form's constructor is so that the controls all get initialized... to: The InitializeComponent() method is called inside the form's constructor so that the controls all get initialized --- (199) second answer change "one that's declare inside a field and called..." to "one that looks ljust like a field to other objects, and called..." {199} fourth answer, second paragraph Remove the sentence "C# was designed to save you from writing redundant code." Also, change "get {" to "set {". {199} sixth answer Add a fourth line with just a closing bracket } to the first code block The second code block has a line break or indentation problem -- the third opening bracket { ran onto the next line and it looks odd. If you just expand the whole NDQ frame by a millimeter or two, it should correct the problem. [200] - this Sharpen Your Pencil needs to be redone. Here's the new code for the class: public class CableBill { private int rentalFee; public CableBill(int rentalFee) { this.rentalFee = rentalFee; discount = false; } private int payPerViewDiscount; private bool discount; public bool Discount { set { discount = value; if (discount) payPerViewDiscount = 2; else payPerViewDiscount = 0; } } public int CalculateAmount(int payPerViewMoviesOrdered) { return (rentalFee - payPerViewDiscount) * payPerViewMoviesOrdered; } } and here's the new code for the three questions. question 1: CableBill january = new CableBill(4); MessageBox.Show(january.CalculateAmount(7).ToString()); question 2: CableBill february = new CableBill(7); february.payPerViewDiscount = 1; MessageBox.Show(february.CalculateAmount(3).ToString()); question 3: CableBill march = new CableBill(9); march.Discount = true; MessageBox.Show(march.CalculateAmount(6).ToString()); {201} - answer Remove the ) at the end of the second paragraph Remove the ) at the end of #1. Then add this sentence to the end of #1: "(It's called camelCase because it starts with a lowercase letter, and additional words are uppercase so they resemble humps on a camel.)" [202], The answers to the Sharpen Your Pencil on page 200 are: question 1: 28 question 2: won't compile question 3: 42 (203) Step 1 in Exercise; CalculateCostODecorations() is missing an "f" after the "O". It should be changed to "CalculateCostOfDecorations()". (245) In the "Bee" class diagram, change "pblic" to "public" Add an annotation pointing to the Bee class diagram: "Sometimes we'll show you return values and private members in class diagrams." {254-256} Pages 254-256 have been substantially revised since the first printing to enhance clarity and quality of learning. You can download a PDF containing the revised pages at: http://www.headfirstlabs.com/books/hfcsharp/hfcsharp_ch07_excerpt.pdf (256) Add a No Dumb Questions to this page: Q: I still don't quite get how interfaces improve the beehive code. You'll still need to add a NectarStinger class, and it'll still have duplicate code... right? A: Interfaces aren't about preventing you from duplicating code. They're about letting you use one class in more than one situation. The goal is to create one worker bee class that can do two different jobs. You'll still need to create classes for them -- that's not the point. The point of the interfaces is that now you've got a way to have a class that does any number of jobs. Let's say you have a PatrolTheHive() method that takes a StingPatrol object and a CollectNectar() method that takes a NectarCollector object. But you don't want StingPatrol to inherit from NectarCollector or vice versa -- each class has public methods and properties that the other one shouldn't have. Now take a minute and try to think of a way to create one single class whose instances could be passed to both methods. Seriously, put the book down, take a minute and try to think up a way! How do you do it? Interfaces fix that problem. Now you can have create an IStingPatrol reference which -- and that reference can point to any object that implements IStingPatrol, no matter what the actual class is. It can point to a StingPatrol, or a NectarStinger, or even a totally unrelated object. If you've got an IStingPatrol reference pointing to an object, then you know you can use all of the methods and properties that are part of the IStingPatrol interface, regardless of the actual type of the object. But the interface is only part of the solution. You'll still need to create a new class that implements the interface, because it doesn't actually come with any code. Interfaces aren't about avoiding the creation of extra classes or avoiding duplicate code. They're about making one class that can do more than one job without relying on inheritance, because inheritance brings along a lot of extra baggage -- you'll have to inherit every method, property and field, not just the ones that have to do with the specific job. Can you think of ways that you could still avoid duplicating code while using an interface? You could create a separate class called Stinger or Proboscis to contain the code that's specific to stinging or collecting nectar. NectarStinger and NectarCollector could both create a private instance of Proboscis, and any time they need to collect nectar, they'd call its methods and set its properties. (259) step 7 Change "Update your button so that the object initializer sets the FunnyThingIHave property, and the button calls" to "Update your button so that it calls" (259) small typo at top right of page. The second "accessor" is misspelled "accssor". (263) The two code blocks should be in the same font -- reduce the font size for the top code block so it matches the bottom one. {266} SYP solution #1 should be "0 and 6" Also, remove the second annotation ("All of these objects...") (274-275) - Turn this into a 1-2-3 spread (like pages 258-259)? There will be a (1) above "public interface IClown {", a (2) above "public class FunnyFunny : IClown {", a (3) on page 275 above "public class ScaryScary : ...", and a (4) above "private void button1_Click...". Here's the text: (1) Here are two interfaces. IClown defines a clown who honks his horn and has a funny thing. IScaryClown inherits from clown. A scary clown does everything a clown does, plus he has a scary thing and scares little children. (2) The FunnyFunny class implements the IClown interface. We made the funnyThingIHave field protected so that it can be accessed by any instance of a subclass of FunnyFunny. (3) The ScaryScary class implements the IScaryClown interface. It also inherits from FunnyFunny, and since FunnyFunny implements IClown, that means ScaryScary does too. Take a look at how the ScareLittleChildren() method accesses the funnyThingIHave backing field -- it can do that because we used the protected access modifier. If we'd made it private instead, then this code wouldn't compile. (4) Here's a button that instantiates FunnyFunny and ScaryScary. Take a look at how it uses as to downcast someFunnyClown to an IScaryClown reference. (276) second answer Add a sentence to the end of the answer, right after "store data by itself.": A property is a way to make something that looks like a field to other objects, but since it's really a method it doesn't actually store any data. {277} class diagram The arrows in the class diagram should be solid, not dotted. {279} code at the bottom of the page in the code under button1_Click, change "MarsMission" to "Mars" in the code under button2_Click, change "VenusMission" to "Venus" (280) headline Change the headline to: "Like we said, some classes should never be instantiated" (281) change last sentence of body text to: So let's implement it! Once we do, the error will go away. Any time you extend an abstract class, you need to make sure that you override all of its abstract methods. Luckily, the IDE makes this job easier. Just type "public override" -- as soon as you press space, the IDE will display a drop-down box with a list of any methods that you can override. Select the SetMissionInfo method and fill it in: (281) annotation, first line Change "is just like an interface" to "is just like what you'd see in an interface" {281} code at the bottom of the page change "SetMissionInfo" to "public override SetMissionInfo" and add an annotation pointing to "override" that says: "When you inherit from an abstract class, you need to override all of its abstract methods." (289) second paragraph, last line Change "check it off the list" to "check it off the following list" {291} code under step 6 Change both instances of "read-only DoorLocation" to "DoorLocation" Change both instances of "DoorDescription" to "read-only DoorDescription" {301} about two thirds of the way down the page -- the fourth annotation's arrow is pointing at it. Change this: while (hidden) { to this: while (!hidden) { (312) fourth annotation on the right Change: This shows "30", 10 * 3. to this: since Fetch has an index of 10, this statement sets score to 30. (322) first annotation, last line Change "and limit the type" to "which limits its members to that type" (330) first paragraph, second line Change "to build your own sorting logic" to "to build a separate class to help the List sort out its members" (331) remove the top annotation ("Console applications that...") (331) #2, second paragraph, first line Change "box underneath it, when you" to "box underneath it. When you" (335) first annotation The annotation should point to "dic-tion-ar-y" and not the text underneath it. (335) second annotation on the right pointing to TKey and TValue Change "The first item" to "These represent types. The first type" (339) 4th line of body text at the top of the page change "obects" to "objects" {367} In the second paragraph, change "Transparent" to "Color.Transparent (if you use the Properties window to set the propery, just type it into the BackColor row)." Add an annotation in the top right corner pointing at the screenshot: "You can set a PictureBox's BackColor property to Color.Transparent to let the form's background picture or color show through any transparent pixels in the picture." (369) Add an annotation in the bottom left-hand corner pointing to the last line of code: "All the other weapons' borders should be turned off." {370} top annotation Change "the Rectangle class" to "Rectangle and Point" (372) Add an annotation pointing to the Mover box: "We added return values and parameters to this class diagram to make it easier for you to see what's going on." (376) Change the annotation in the middle from "The NearPlayer() method uses the Mover.Nearby() static method to figure out if the enemy is near the player." to "The Enemy class inherited the Nearby() method from mover, which it can use to figure out whether it's near the player." (378) In the code, 10 lines from the bottom of the page: Add an annotation that points to this line of code: "if (Nearby(enemy.Location, target, radius)) {" it should say: "The Nearby() method in the Mover class only takes two parameters, a Point and an int, and it compares the Point to the Mover field location. You'll need to add an overloaded Nearby() that's almost identical, except that it takes three parameters, two Points and a distance, which compares the first Point to the second Point (instead of location)." (384) second paragraph, second line: change "and add way" to "and add a way" third paragraph, second to last last line: change "user-friendly ending -- maybe" to "user-friendly ending? Maybe you can" (385) thought bubble Move the underline so that it's under "am" (399) first paragraph, first sentence Change "An OpenFileDialog box object" to "An OpenFileDialog object" (406) fifth annotation that starts "In this case" Change "the Log stream, so the Dispose()" to "pointed to by sw -- which was declared in the using statement, so the Dispose()" {406} bottom block of code, first two lines that start with "using" Remove the semicolons at the end of these two lines and add an extra closing parenthesis at the end of each line. The code should be: using (StreamReader reader = new StreamReader(Òsecret_plan.txtÓ)) using (StreamWriter writer = new StreamReader(Òemail.txtÓ)) (421) - first line of code ("[Serializable"]) under step #1 Add an annotation pointing to [Serializable]: You need to add this attribute to the top of any class in order to serialize it. {421} third-to-last line of code Remove the semicolon from this line: }; {421} - code Change both instances of "Joe" to "joe" -- not capitalized also, in the last block of code, change both instances of "bf" to "formatter": BinaryFormatter formatter = new BinaryFormatter(); joe = (Guy)formatter.Deserialize(input); In the second-to-last line of code, change "CheckGuys();" to "UpdateForm();" Also, the screenshot is incorrect, and has been replaced in this reprint. {422} step 3, second line change PrintCards to DealCards {422} code, fifth line from the bottom change "DeckToDeal.Deal();" to "DeckToDeal.Deal(0);" {423} step 4, second-to-last line o code Swap the line of code that starts "DealCards(..." with the preceding line so it's before the closing curly brace, and indent it by another two spaces. (423) second annotation The arrow for this annotation is slightly misaligned -- it needs to point to "(Deck)" (425) step 3, first paragraph, last line: change: then paste the letters over "Eureka!" so it looks like this: to: then paste the letters over "Eureka!" and add the Encoding.Unicode parameter, so it looks like this: {425} step 3, line of code Add a third parameter, Encoding.Unicode -- it should look like this: File.WriteAllText("eureka.txt", "[HEBREW CHARACTERS HERE]", Encoding.Unicode); (424) Behind the Scenes box, second line of text at the top Make "unicode" uppercase - "Unicode" {430} second block of code in the first line, change 227 to 218 in the second line, change 275 to 266 (434) last answer, sixth line: change "add a third parameter" to "change the third parameter" {436} seventh line of code change "save_Click" to "open_Click" (465) bottom right-hand corner picture The "EX" label on the Exception object should have a white text background, not transparent, so it looks white and not grey {468} third line ("throw new ArgumentNullException();") change "ArgumentNullException();" to "ArgumentException();" and add an annotation pointing to it: Your methods can throw this exception if they get invalid or unexpected values in their parameters. (471) bottom right-hand corner box There should be no line break between "new" and "YourClass();" (472) sixth annotation change "You'll often see one using statement inside of another." to "You'll see nested using statements like this when you need to declare two IDisposable references in the same block of code." (472) seventh annotation the arrow is pointing to an underscore that's misaligned -- it should be under "Log" {473} fourth answer, last paragraph change "SomethingRisky()" to "DoSomethingRisky()" (474) - second paragraph, first line change "Take a look at the DivisorCalculator" to "Take a look at this Calculator class" {484} first annotation that starts "When the ball gets hit" change BallHasBeenHit() to OnBallInPlay() (487) fourth annotation that starts "Here's what each object" change this annotation to: Here's what each object that handles the event gets to work with. It also gets a reference to the object that raised the event. (488) bottom annotation starting with "When you use EventHandler..." Add another sentence to the end of this annotation: sender is a reference to the object that raised the event, and e is a reference to an EventArgs object. (498) first annotation remove the word "pre-made" from the second line of the annotation {502} step 1, first paragraph, second line Change "AddSecretIngredient.cs" to "GetSecretIngredient.cs" {506} third paragraph change both instances of "ListenForClues()" to "treasure_RunForCover()" (509) fifth bullet point Change "You chain several" to "You can chain several" (510) first answer, second paragraph, last line The last word of the last sentence is cut off -- add the word "constructor." {511} second italicized paragraph near the middle of the page change both instances of "ListenForClues()" to "treasure_RunForCover()" (520) bottom paragraph Add an annotation at the bottom of the page pointing up at the bottom paragraph: Since this simulator will be animated, we'll be drawing it frame by frame. We'll use the words "frame," "cycle," and "turn" interchangeably. (521) second annotation Remove the asterisk from the beginning of the annotation. Change "We used" to "You'll use". (524) second line Change "its" to "it's" (536) first two annotations (537) second annotation The annotations and their arrows are misaligned. They need to be shifted down. (538) step 1, second line Change "hive and world in the constructor" to "hive and world as parameters to its constructor" (538) step 5, first line Change "The World class keeps up with all the bees" to "The World class uses a List of Bee objects to keep track of all the bees" (539) second question Change "Point object" to "Point" (539) last answer Add this after the first sentence: "Plus, it'll come in handy when we do the animation." {540} first annotation Change "local variables" to "private fields" {540} second annotation that starts "More basic code...", second line Change "assign it locally" to "set a private field" (541) bottom The annotations are overlapping the box (544) first annotation in the left Change "dropdown that appears on the form" to "dropdown that appears on the ToolStrip when you're in the form designer" (544) second annotation on the left Change "Use the dropdown" to "Use the dropdown that appears on the StatusStrip in the designer" (544) first annotation on the right that starts "Each of these labels" Add a new annotation above this one with an arrow pointing down at it. It should say: The labels in the right-hand column will show the stats. Name them "Bees", "Flowers", "HoneyInHive", etc. (547) Add the "Behind the Scenes" picture (like on p576) to the upper right-hand corner of the page. (549) exercise box Add another annotation underneath the first one that says: "Just double-click on a ToolStrip button in the designer to make the IDE add its event handler, just like a normal button." (561) left-hand annotation The annotation is pointing to an underline, but the underline is misaligned--it needs to be moved up (566) first line Change "great simulator" to "cool simulator" (566) step 2 Change "We'll add a Print button to the stats window" to "We'll make the Print button in the stats window work" Change the two sentences underneath that to: "The stats window has working Open and Save buttons, but the Print button doesn't work yet. We'll be able to reuse a lot of the graphics code to get the Print button on the ToolStrip to print an info page about what's going on. (574) screenshot Add an annotation pointing to the screenshot that says: "Double-click on Resources.resx to bring up the Resources page." (575) step 3 add an annotation pointing to the line of code under step 3 that says: "When the program's running, each picture is stored in memory as a Bitmap object." (576) step 2 change "and and" to "add and" (576) behind the scenes box, last paragraph Change "you see in the form's Properties window" to "you see in the Properties window for any control" (582) annotation that starts "Set the form's BackgroundImage" change "inside hive picture." to "inside hive picture, and its BackgroundImageLayout property to Stretch." (591) step 2, first line change "an array of four of them" to "in this case, an array of four of them" (591) block of code under step 2 Add an annotation pointing at this code that says: "These lines take each of the Bitmap objects that store the bee pictures and shrink them down using the ResizeImage() method we wrote." (593) last paragraph, last line Change "trickier..." to "slower..." (606) first answer, last line change "programmatically" to "in code" (606) fourth answer, fifth line from the bottom change "got CreateGraphics() method" to "got a CreateGraphics() method" (606) - fifth answer, first paragraph, second sentence change "When a class implements IDisposable, any time you instantiate it you should call its dispose() method." to "When you instantiate a class that implements IDisposable, you should always call its Dispose() method when you're done with the object. That way it knows to clean up after itself." (606) last answer Remove the last sentence ("You'll see more about that in just a minute.") (607) second paragraph change "most amateur computer games..." to "some amateur computer games, for example." (615) step 5, last line of code Add an annotation pointing to "DrawBee" that says: "We'll reuse our DrawBee() method from a few pages ago." (625) fifth annotation that starts "You can leave out" Replace this annotation with: "Don't worry about drawing the Clone and List objects -- just add the objects for the Captain, the Swindler, the clone factory and Swindler's escape plane." (629) code in the bottom right-hand of the page indent the "clones.Remove(clone);" line by three spaces (633) second annotation starting "This is straight" change this annotation to: "The Clone will create the C:\Temp directory and serialize itself out to a file called Clone.dat." (633) third annotation starting "You could set a class" change this annotation to: "We hardcoded the filename -- we included them as string literals in the code. That's fine for a small demo program like this, but it's not the most robust design. Can you think of problems this might cause, and how you could avoid them?" {638} first block of code, first line change 37 to 25 {644} third answer, second sentence change "familiar field from" to "familiar code from" (646) top paragraph, first line Add an annotation pointing to the word "sealed" in the first line that says: "Remember the sealed access modifier from Chapter 7? It's how you set up a class that can't be extended." (647) second answer, first two sentences ("Sure. But then you'd need ... would have to change.") Change these sentences to: "If you can extend the class, then you'll usually end up doing that -- extension methods aren't meant to be a replacement for inheritance. But they come in really handy when you've got classes that you can't extend." (648) first paragraph Add this to the end of the first paragraph: "Create a new project, and add a file called MyExtensions.cs." {648} step 1, first line of code change "Emergency" to "MyExtensions" {648} step 3, first line of code change "HumanExtensions" to "StringExtensionMethods" (648) step 4, first sentence change "Add using Emergency; to your code." to "Now go to your form code and add using MyExtensions; to the top, and add a button to the form so you can try out your new extension method inside its event handler." (655) bottom left-hand annotation Change "All of the Objectville" to "All of the Objectville Paper Company" (655) Brain Power box change "Objectville paper" to "Objectville Paper Company data" (656) add an annotation pointing to the first paragraph: We gave you Ready Backe Code for the LINQ query in Chapter 12. We'll see exactly how it works in a few pages. (658) "var" tool tip box Put the two lines of code in boldface (659) Brain Power change "Jim" to "Jimmy" (660) first sentence Change "It's easy to mine Jimmy's data" to "Jimmy could analyze his comic book data" (671) first paragraph, third line change "class with two fields" to "class with two automatic properties" (683) left-hand annotation starting with "The spacebar shoots" Change "there can only be two shots" to "there can only be two player shots" (683) right-hand annotation that starts "The game should keep" change "all keypresses" to "which keys are currently being held down" (685) bottom annotation Change "The Stars keeps" to "The Stars object keeps" {686} second annotation change "DisplayRectangle" to "ClientRectangle" (687) bottom subheading change "Adjust the timer" to "Adjust the timers" (689) second to last paragraph, last line change "Refresh()" to "Invalidate()" (689) last paragraph Add this sentence to the end of the paragraph: "You can start the game out in this state, so the user has to hit S to start a new game." (691) second paragraph replace the whole paragraph with this text: So the form should have a Paint event handler (make sure you set the form's DoubleBuffered property to true!). You'll delegate the rest of the drawing to the Game object by calling its Draw() method every time the form's Paint event fires. {694} second paragraph Change DisplayRectangle to ClientRectangle (704) 1st paragraph, 3rd line; "Add add" s/b "Add" (707) add an annotation pointing to the last paragraph: Plus, it'll even figure out that it should create a static method, since it doesn't use any fields. (710) Annotation in bottom-right corner of page, 4th line; "applicaiton" s/b "application" (712) 3rd paragraph, 1st line; Missing period. "application Just" s/b "application. Just"