C#

The Bonus Site for C# For Dummies
csharp102.info

Errata: Known Errors in C# 2008 For Dummies

Note: As of July 2010, I have gathered all errors previously shown on multiple Web pages onto this one page. This should make for easier lookup and checking off as you make corrections.

Report an Error Not Listed in These Error Pages

As boo-boos are discovered, we'll post them here so you can make the necessary hand corrections in your copy of the book.

If you're looking for help with a balky program of your own, please try Microsoft's C# site, the C# Forum, or other Web information sources before emailing the authors. We love to help, but please keep in mind that we have too many irons in the fire to be a Help Desk.

I apologize for the inconvenience these errors will cause you - but at least you have the correct information on this page. I've categorized the errors so you can focus first on the most substantive ones.

If you spot an apparent error, please look on this page before you report the error. You can use the link above to Report Errors on the Site or in the Book (or in the example code).

NEW: As of 4-21-08, I'm dating entries to help you locate what's new. Dates will look like

[4-21-08].

Errors in the Book

The items in this category are errors in the printed book.

Errors in the Example Code Downloads

The items in this category are errors in the code downloads on the Example Code page.

Errors in Bonus Chapters and Articles

The items in this category are errors in the bonus chapters and articles you can download from the Bonus Chapters and Aritcles pages.

Errors Due to a Late Chapter-Numbering Change

Just before the book went to the printer, we dropped one of the Bonus Chapters but failed to correct some cross-references to other Bonus Chapters. Follow the link above for details.

Tips and Techniques

The items in this category are things that I would have liked to get into the book but didn't. They should improve your code and/or your coding technique. Follow the link above for these items.

Errors in the Book

Here are the mistakes in the printed book. I keep trying to get them corrected in future printings.

  • Page 6, under "About the Web site." I missed changing this paragraph after we decided to put the bonus materials on a Web site rather than on a CD-ROM. The paragraph should read as follows:

    The Web site contains a host of goodies. First, you find an expanded collection of all the source code from this book. Second, you find seven additional bonus chapters. Finally, you find a collection of resources. These include a Frequently Asked Questions (FAQ) page, a variety of bonus articles plus references to useful books and articles you can find elsewhere, and links to several very useful utility programs, such as SharpDevelop, NUnit, and Reflector.
  • Page 17, list item b, last sentence (in parentheses). Change the following:

    (The directory may already exist if you've installed the example programs from the Web site.)

    to the following:

    (You need to create the following directory: C:\C#Programs. Then install the programs there from the Web site.)
  • Page 20, first line on page. Change DOS to Windows. (DOS died a while back--it's all Windows now.)

  • Page 21, first line of code in the upper code example. The first line of code here should be in boldface type.

  • [6.16.10] Page 29 in the 2008 book (page 27 in the 2010 book), in the section What's an Int?, last sentence in the section,

    (The variable n doesn't lose its value when you assign its value to m. It's like cloning n.)

    should read

    (The variable m doesn't lose its value when you assign its value to n. It's like cloning m.)

  • [4.2.08] Page 31, the BigInteger section. Well, this one's a bit of a doozy. The C# specification document listed BigInteger as one of the new features, so I dutifully wrote about it -- but didn't really check it out or try using it. What use do I have for such a beast? What use do you have? Most For Dummies readers won't have ANY use for it in all likelihood. As it turns out, there is a BigInteger class, but it's hidden away inside the cryptography library in the .NET Framework 3.0 libraries. Not public, not directly usable in C#. There is a sort of twisted back-door way to get at it, by using a companion .NET language called J# (a part of Visual Studio 2005, still supported by Microsoft until 2015, but dropped from Visual Studio 2008, though still available separately from Microsoft). J# is a pretty lame tool that uses Java-like syntax on .NET. J# does make a big integer implementation available. You have to include a J# library in your C# program to use it. So it is there, sort of. Anyway, my apologies for not having checked it out more carefully before writing about it.

    [7.24.10], The good news! BigInteger has actually made it into .NET 4.0 and C# 4.0. You don't need to go anywhere near J#. You can find the BigInteger class in the System.Numerics namespace in the Microsoft MSDN documentation: BigInteger

  • Page 36, first line in the paragraph below the code example. The word second should be first.

  • Page 64, first line of second paragraph below the code. This line should read: The example program uses the ReadLine() command to read in what the user ...

    Go to Top

  • Page 86, just before the heading "Don't goto pieces." I should have added the following short paragraph:

    You can nest if and switch statements within each other too.
  • Page 99, in the listing of the BubbleSortArray program, 17 lines down from the top of page 99. The statement assigning the planets array to the sortedNames array before sorting is a coding error--here's the line:

    string[] sortedNames = planets;

  • This line does NOT copy the contents of planets into sortedNames, as I indicated. Instead, it just points the sortedNames array reference to the planets reference. Both arrays point to the same data. Thus when I sort sortedNames, I sort both arrays in effect. Not what I intended. What I needed to do was use the Array.CopyTo() method to copy planets into sortedNames. The corrected code looks like the following:

    string[] sortedNames = new string[planets.Length];
    planets.CopyTo(sortedNames, 0);
    Array.Sort(sortedNames);

    This creates the sortedNames array, then copies planets to sortedNames, and sorts sortedNames. The planets array is not sorted--which is what I intended.

  • [10.13.09], Page 105, second line of code under Using Lists should read:

    myMP3s[0] = new MP3("Norah Jones");

    The first element in that line changes from myPP3s to myMP3s.

  • Page 106, fourth paragraph. There should be an "On the Web" icon by this paragraph, which begins "The ListCollection...."

  • [7.26.09], Page 106, last three lines of code in the first shaded code block should read as follows (adding to nameList, not sList):

    nameList.Add("one");
    nameList.Add(3); // Compiler error here!
    nameList.Add(new Student("du Bois")); // Compiler error here!
  • Page 106, first block of code on the page. All references to 'sList' should be to 'nameList'.

  • Page 110, line 2 in the first paragraph, following the first code fragment. The Help search instruction should read "Look up dictionary in the Help Index. This gets you to the entry 'Dictionary(Of TKey, TValue)'. Click the 'initializing' entry under that item." (Note that this is Visual Basic syntax, but it gets you to C# information too.)

  • [7.26.09], Page 110, last three code lines on the page should read as follows (adding to numList, not numbers):

    numList.Add(1); // Add elements one at a time.
    numList.Add(2);
    numList.Add(3); // ...teeedious!
  • Go to Top

  • Page 118, 3rd line on the page. It would be helpful to note that Bonus Chapter 4 is on this Web site, on the Bonus Chapters page.

  • [7.26.09], Page 124, code block at the bottom of the page. The if statement needs an extra set of parentheses--around the whole compound comparison statement:

    if((String.Compare("exit", source, true) == 0) || (String.Compare("quit", source, true) == 0)) ...
  • Page 171, Figure 8-1. The notation "Output(funcString)" should read "Output(someString)" as it appears in the surrounding text.

  • Chapter 10 (page 209) should appear as part of Part IV, Object-Oriented Programming, rather than Part III, Using Objects. You see this error in the Table of Contents and later in the book.

  • Page 225, first paragraph. The phrase "your Web site" should be "my Web site." You may not even have one!

  • Page 267, 3rd line of program output near bottom of page. The code above that output actually prints "now creating...," with a lowercase 'n,' not "Now creating...," with an uppercase 'N.'

    Go to Top

  • Page 268, first line of output section at bottom of page. The line printed is actually "Invoking SubClass() default".

  • Page 273, Figure 12-1. The middle line in the figure has an extraneous parenthesis. Delete the middle one, ')'.

  • Page 309, second block of code. The return statement in the CreateRecorder method is missing a required cast. Since the method returns an IRecordable, not a Pen, the newly created Pen must be cast to an IRecordable. The code should look like this:

    if(recorderType == "Pen") return (IRecordable)new Pen();
  • Page 312, first line of code on the page. The Console.WriteLine call is missing a quote mark on its format string:

    "{0}, disp.Display()

    should be

    "{0}", disp.Display()
  • [9-18-09], Page 315, second line of code at top - the body of the Student constructor. The line reads:

    { Name = Name; Grade = grade }

    The second occurrence of Name should be all lowercase: Name = name

  • Page 319, Figure 14-1. In the uppermost box of the diagram, "iPet" should be "IPet" with a capital I.

  • Go to Top

  • Page 319, second paragraph below Figure 14-1. You should see an On the Web icon next to this paragraph. [4-21-08]

  • [4.3.10], Pages 339-342, the button1_Click() method shown on page 342 works better if you move the lines

    // Clear the bar so it can be used again.
    progressBar1.Value = 0;

    from the end of the method to the beginning:

    // This one is for the Click to Start button.
    private void button1_Click(object sender, EventArgs e)
    {
    // Clear the bar so it can be used again.
    progressBar1.Value = 0;
    // If using a raw delegate, instantiate the delegate, telling it what method to call.
    UpdateProgressCallback callback = new UpdateProgressCallback(this.DoUpdate);
    // Do something that needs periodic progress reports.
    // This passes a delegate instance that knows how to update the bar.
    DoSomethingLengthy(callback);
    }

    If you've downloaded the code for Chapter 15 from the Example Code section on this site, you can try it both ways.

  • [10.31.09], Page 341, first line of code at top of page. There should be a 'new' call before the callback delegate on the right side of the assignment. The line should read:

    UpdateProgressCallback callback = new UpdateProgressCallback(this.DoUpdate);
  • Page 361, first paragraph. Note that the "Extra Example 6" referred to is in the LambdaExamples program on this Web site.

  • Page 372, short paragraph following the one marked with a Tip icon. The phrase "from the following array" should read "from the given array."

  • Page 374, first item in the bulleted list--the Grouping paragraph. The second sentence makes better sense if you insert a dash or colon between "size" and "all customers".

  • Page 376, last bullet item at the bottom of the page. The word "alphabetized" should be "ordered".

  • Page 401, last paragraph. Instead of being in Bonus Chapter 5, the example mentioned is in the article "Querying an Object As a Collection with LINQ" on this Web site. Click the Articles link on the Home page.

  • Go to Top

Errors in the Example Code Downloads

  • [6.5.10], ConvertTemperatureWithRoundoff Program, Chapter 2. The downloadable example for Chapter 2 apparently includes an incorrect version of this program. Visit the Code Examples page on this site and see the Code Fixes from Book Errata section near the bottom. That location has a download that corrects this program. (Note that the download for Chapter 2's code still has the incorrect code.)

  • BubbleSortArray Program, Chapter 5. A reader reports a coding error in the BubbleSortArray program listed on pages 98-100 in the book. The error is in the Program.cs file. See the Page 99 writeup in Book Errors for details.

  • [10-27-08], HashSetExample Program, Chapter 5. A reader reports an incorrect comment in the code example's Program.cs file. It's in the code segment headed:

    Console.WriteLine("\nExcluding items from a list:");

    Specifically, the last line of this comment

    // ExceptWith() removes any items in remainder that are
    // also in queue: 1, 3, 5, 7,
    // leaving remainder with 9, 11, 13, 15. Stage 2 of 2.

    should omit 9--that's excluded, not remaining after calling

    unique.ExceptWith(queue);

    So the corrected comment should read:

    // leaving remainder with 11, 13, 15. Stage 2 of 2.

Go to Top

Errors in the Bonus Chapters or Articles

  • In the article "Enumerating the Charms of the Enum," page 6, last paragraph on the page (marked Code Example), refers to code "on the CD." There is no CD in this edition. All articles and their code are on this Web site. The paragraph should read:

    The EnumFun example available with the download for this article shows off some of enum's many talents, including using enums in if and switch....

Go to Top

Erroneous References to Bonus Chapters

Near the end of preparing the book, we dropped a bonus chapter (whose contents are still available on this site in the listings on the Articles page). Unfortunately, the editors missed a, um, uh, few cross-references to Bonus Chapters whose numbers changed. Sigh. Here they are.

  • Page 3, last line of the first paragraph. The reference to Bonus Chapter 6 should be to Bonus Chapter 5.

  • Page 14, next-to-last line on the page. The reference to Bonus Chapter 6 should be to Bonus Chapter 5.

  • Page 94, next-to-last line in the gray sidebar. The reference to Bonus Chapter 6 should be to Bonus Chapter 5.

  • Page 105, line 4 of the paragraph titled "Going generic." The reference to Bonus Chapter 8 should be to Bonus Chapter 6.

  • Page 116, last line on the page. The reference to Bonus Chapter 7 should be to Bonus Chapter 6.

  • Page 172, first paragraph. The Bonus Chapter 5 referred to was dropped at the last minute and its topics parceled out to a set of articles. You can find the information referred to in this paragraph in an article on this Web site titled "Passing arguments to a program." On the Home page, click Articles.

  • Page 145, last paragraph. The topic in Bonus Chapter 5 is now an article on this site, titled "Converting Between Byte and Char Arrays." On the Home page, click the Articles link.

  • Page 239, last paragraph before the heading that begins "Initializing an object ...." The reference to Bonus Chapter 6 should be to Bonus Chapter 5.

  • Page 266, parenthetic sentence below first code example. The reference to Bonus Chapter 7 should be to Bonus Chapter 6.

  • Page 310, next-to-last line of first paragraph in the section "Using C#'s predefined interface types." The reference to Bonus Chapter 8 should be to Bonus Chapter 6.

  • Page 336, last paragraph before "Pass me the code ...." The reference to Bonus Chapter 8 should be to Bonus Chapter 6.

  • Page 357, line 3 of the paragraph just before the one marked with a Remember icon. The reference to Bonus Chapter 7 should be to Bonus Chapter 6.

  • Page 375, last paragraph. The reference to Bonus Chapter 8 should be to Bonus Chapter 7.

  • Page 376, last paragraph before the heading "What can I do ...." The reference to Bonus Chapter 7 should be to Bonus Chapter 6.

  • Page 396, second paragraph, just before the heading "What's inside ...." The reference to Bonus Chapter 7 should be to Bonus Chapter 6.

Go to Top

    Tips and Techniques

    • The following tips and techniques are things I wish I had gotten into the book but didn't. These will save you time or add to your programmer's tool kit.

      • Commenting Out Lines of Code

        Page 162, paragraph 6, refers to "commenting out" some lines of code. It would be helpful here to explain the idea of "commenting out" lines of code. Often you need to remove lines of code, but you'd rather not just delete them. It's common practice for programmers to turn those lines into C# comments, preceded by "//". Visual Studio helps with this by providing a toolbar button called "Comment out the selected lines. (Ctrl+E,C)". The button looks like several lines of code in black, with several lines shown as being commented out, in blue. There's also an adjacent button to "uncomment" lines. To comment out lines, select the lines in the C# editor, then click the comment-out button. To uncomment, select the lines, then click the uncomment button.

      • Method Signatures

        Page 167, item 3 in the list. It would be helpful to define the term "signature" mentioned here. A method's signature consists of its name, its return type (or void), and the types of its parameters.

      • Go to Top