Errata

Learning C# 3.0

Errata for Learning C# 3.0

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.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
Answers Appendix
Top of page, first answer.

http://my.safaribooksonline.com/9780596155018/chapter_4_operators

Solution to Question 4-2. To assign the same value to multiple variables, simply chain the assignments, like this:

int a = b = c = d = 36;

The above statement creates 3 errors:
The name 'b' does not exist in the current context
The name 'c' does not exist in the current context
The name 'd' does not exist in the current context

The following works:
int a,b,c,d;
a = b = c = d = 36;

Shannon Barta  Mar 13, 2009 
PDF Page ch 19
Chapter 19 Code does not work

The FileCopier code presented as the basis for Chapter 19, does not work. I am running Windows 7. When displaying the treeview's they only show the first few folders on the hard drive. When I could not make this software work myself, I downloaded the source code from your site and ran it directly, unmodified. Your source failed as well. According to MSDN, treeview should work under all windows platforms, so I have to assume there is something wrong with the author's code.

Anonymous  Jan 31, 2010 
17.3
Lambda Expressions

17.3 Lambda Expressions:

( ) => {Console.WriteLine("No parameters here."}};

Should be:

( ) => {Console.WriteLine("No parameters here.")};

Anonymous  Feb 16, 2010 
Printed Page 40
In "The Macro Explorer Window" paragraph

"The Macro Explorer is the one of the main tools" should be "The Macro Explorer is one of the main tools"

Stephen Korow  May 21, 2009 
Printed Page 47
sample code

On page 47 is listed the following sample code:

int myDouble = 4.7;
// other code here...
int myInt = (int) myDouble; // explicit conversion

Shouldn't the line;

int myDouble = 4.7

be

double myDouble = 4.7;

for this to make sense?

Anonymous  Feb 13, 2009 
Printed Page 52
3rd code example on page

Code example for the Console.WriteLine method makes it appear as though you can enter the quoted string on more than one line, but this will not compile - you will get a 'newline in constant' error message due to a newline character (an actual one, not an escaped character) in the string. The text does not explain that the string is split to fit on the printed page, but must all be entered on one line in the editor.

Tim Jones  Aug 11, 2009 
Printed Page 57
code snippet before last paragraph

int myDouble = 4.7;
should be
double myDouble = 4.7;

Stephen Korow  May 21, 2009 
Printed Page 57
code example at the bottom of the page

shouldn't myDouble be of type "Double" instead of type "int". Otherwise, there is no need for the explicit cast. Also, you'll get an error because you are trying to assign the value "4.7" to an int variable.

Stephen Korow  Nov 20, 2009 
Printed Page 57
C# code at the bottom of the page

The code is demonstrating converting a double to an integer. Therefore, the first line of code "int myDouble = 4.7;" should be "double myDouble = 4.7;".

Stephen Korow  Jan 21, 2010 
Printed Page 58
first paragraph

The last sentence of the first paragraph on page 58 states that the reader is almost guaranteed to lose value sooner or later. While I agree with the sentiment, I believe you meant to say that that "you are almost guaranteed to lose a value sooner or later" or possibly "lose precision in a value sooner or later".

Stephen Korow  Nov 20, 2009 
Printed Page 58
first paragraph

The last sentence of the first paragraph is missing an "a". It should read "guaranteed to lose a value".

Stephen Korow  Jan 21, 2010 
Printed Page 77
First example

book r = true;

is supposed to be:

bool r = true;

Lucas Jarmin  May 10, 2009 
Printed Page 77
code example after first paragraph

The third boolean variable is declared with a "book" type. The correct declaraion is:

bool r = true;

Bruce Ring  Jun 30, 2010 
Printed Page 84
Exercise 4-4

This is picky, but units of area and units of volume are not comparable, therefore it doesn't quite make sense to say which result is greater. What high school did the author attend?

Tim Jones  Aug 11, 2009 
103
code example after 3rd paragraph

Console.WriteLine("Enter your input string.") statement needs to end with a semicolon.

Tim Jones  Aug 12, 2009 
Printed Page 181
2nd Paragraph of Setting a Breakpoint section

The sentence reads:

"Open Example 8-1 from Chapter 8, if you haven't already, and click in the gray margin next to the first line of Main()(Tester t = new Tester())."

I believe this meant to say "Example 8-2" as there is no Tester object created in Example 8-1.

Phillip McCollum  Dec 16, 2009 
Printed Page 213
middle of page

The middle of the page contains this code example:

rectangularArrayrectangularArray[i,j]

That probably should be:

rectangularArray[i,j]

Bruce Ring  Jul 05, 2010 
Printed Page 226
third code example

You intend to derive MyOtherClass from MyClass. The code example has this reversed.

Eric Bank  Mar 22, 2009 
Printed Page 230
In "Overriding Virtual Methods"

In the first code example in "Overriding Virtual Methods," the name of the method is erroneously changed from DrawControl to DrawWindow.

Lucas Jarmin  Jun 18, 2009 
Printed Page 231
2nd paragraph

This is very minor, but I thought it may be helpful to the author.

In the second paragraph on page 231, the sentence begins "But because ListBox is a Control" the "is a" portion is not all italicized ("a" is not italicized).

Hope this is helpful.

Anonymous  Apr 21, 2010 
Printed Page 231
4th paragraph

On the for loop explanation i<3 is used instead of ControlArray.Length.
The result is the same though.

Stefanos Vyzikidis  Nov 16, 2010 
Printed Page 233
Throughout page

Don't you think you should have made explicit the fact that if you polymorphically call a method that uses new instead of override, that the base class version of the method executes?

Anonymous  Mar 22, 2009 
Printed Page 235
first paragraph

The keywords abstract and public should be interchanged in position.

abstract public void DrawControl();

should be

public abstract void DrawControl();

Paul Lin  Oct 30, 2009 
Printed Page 249
Second Paragraph

I dont know that it is proper to say this is a mistake or not, but when compiling the code Example 12-2 and 12-3 I noticed 2 warnings as shown below (note I am using VS 2008):

Warning 1 <class> defines operator == or operator != but does not override Object.GetHashCode()
Warning 2 <class> overrides Object.Equals(object o) but does not override Object.GetHashCode()

It would be helpful if the author includes a note about this on p. 249 par. 2 since he is already mentioning how == forces != and vise versa. It would also be helpful if he included an example of what the override function for GetHashCode() should look like. Perhaps something like below is sufficiant:

public override int GetHashCode()
{
return base.GetHashCode();
}

Anonymous  Apr 22, 2010 
Printed Page 254
Paragraph starting with "To implement the conversion operator, ..."

The last sentence of the paragraph reads:
"For example, to convert your Fraction to an int, you do this:"

should read:

"For example, to convert your int to a Fraction, you do this:"

Its only a sloppy error, but it confused me for a couple of minutes that I will never get back.

Anonymous  Mar 23, 2009 
Printed Page 294
Last paragraph before Example 14-1.

I believe what is printed as "...that contains a simple array (myStrings)..." should read "...that contains a simple array (strings)..." if it is to match the code in Example 14-1.

Eric Larson  May 17, 2012 
Printed Page 311-313
Code Example 14-5

While reading the Code Example 14-5 and retyping it I found the "public bool Equals(Employee other)" method confusing. There is no reason for it to be there. Also, lines 20 and 21 are commented out, and they call a method that does not exist. While the example obviously runs fine since it is commented out, it serves no real purpose, it is just confusing.

Once I got to Code Example 14-6 I thought perhaps this would make it more obvious why the author decided to implement this method and have those lines commented out, however I realized those parts in example 14-5 are a very partial implementation of what gets added in 14-6 it has further made me wonder why it was there.

I hope this information is helpful. I could only imagine how tough it is to write a book of this breadth. Thank you for your hard work.

Anonymous  Apr 26, 2010 
Printed Page 313
Code Example lines 9 & 18

In lines 9 & 18 of the code example there are very minor space typos. (just for consistency)

Line 9 reads:
Console.WriteLine("List<int>after sorting:");
It Should read:
Console.WriteLine("List<int> after sorting:");

Line 18 reads:
Console.WriteLine("List<Employee>after sorting:");
It Should read:
Console.WriteLine("List<Employee> after sorting:");

Anonymous  Apr 26, 2010 
Printed Page 330
Exercise 14-1

The wording states "Create an abstract Animal class that has private members weight and name..." If you do exactly as the text states, you cannot access the variables from the derived classes you are then asked to create. The wording should be changed to "protected members..." or not qualify "members" at all.

Josh R.  Feb 04, 2011 
Printed Page 338
Example 15-3, lines 21 & 27

Line 21 reads:

Console.WriteLine(" \nstring s2 = string.Copy(s1); ");

It should read:

Console.WriteLine(" \nstring s3 = string.Copy(s1); ");




Line 27 reads:

Console.WriteLine(" \ns2 = \"Hello\"; ");

It should read:

Console.WriteLine(" \ns1 = \"Hello\"; ");

Anonymous  Jun 24, 2010 
Printed Page 339
3rd paragraph

Exemple 15.3 the book says:
"Now, returning to s1 and s2, which refer to the same object, if you change either
one, for example, when you write:
s1 = "Hello";
s3 goes on referring to the original string, but s1 now refers to a brand-new string.
If you later write:
s3 = "Goodbye";"

It should read s2 instead of s3.
s3 never refers to the original string.

Anonymous  May 26, 2014 
Printed Page 342
End of page below "Here's the output:"

At the end of page 342 below where it says "Here's the output:"

String s3 is 4 characters long.
The 5th character is r

It should say "s3 is 94 characters long", as follows:

String s3 is 94 characters long.
The 5th character is r

Anonymous  Apr 27, 2010 
Printed Page 399
last snippet of code

in the last snippet of code "timeInfoEventArgs" is in Bold. This didn't change from the previous code. The modified code, and the code that is referred to in the test is "delgate". That is what should be bolded.

Stephen Korow  Jan 21, 2010 
Printed Page 400
C# code in the middle of the page

"theClock.OnSecondChange" should be "theClock.SecondChange".

Stephen Korow  Jan 21, 2010 
Printed Page 400
Code example in the middle of the page

"theClock.OnSecondChange" should be "theClock.SecondChanged".

Anonymous  Apr 28, 2010 
Printed Page 400
No Paramater Lamabada example at end of page

At the end of the page, very last line the lambada example has a typo:

() => {Console.WriteLine("No parameters here."}};

Should be:

() => {Console.WriteLine("No parameters here.")};

Notice the curly braces at the end of the statement.

Anonymous  Apr 28, 2010 
Printed Page 401
4 lines down from the top of the page.

On the fourth line down from the top on page 401, the example shows:

n => n * n

it should read:

n => n * n;

Anonymous  Apr 28, 2010 
Printed Page 426
First code example after the heading "Implementing the Copy button event"

In the first code example after the heading "Implementing the Copy button event" it says to input the following code:

private void btnCopy_Click( object sender, System.EventArgs e )
{
List<FileInfo> fileList = GetFileList();

it should be:

private void btnCopy_Click( object sender, System.EventArgs e )
{
List<string> fileList = GetFileList();

Anonymous  Apr 29, 2010 
PDF Page 432
The whole source code

The code explained in that chapter is a whole mess, and worst, the so-called File-Copier just doesn't work.
The explanations aren't accurate.
The code shows a lot of bad programming habits:
- using dir.GetDirectories() to test if drives are ready instead of using the proper way with DriveInfo.IsReady.
- using dir.Exists to test if its a file or a directory instead of testing FileAttributes.Directory, making the code obscur.
- passing a useless parameter ndRoot.Text to the function GetSubDirectoryNodes(), whereas as he stated, it can be retreived just fine with ndRoot. The explanation given for that trick just doesn't make any sense. ndRoot.Text just doesn't need to be passed as argument.
- testing if (isSource) whereas it could be directly passed to the function as argument, since it is tested again inside the function.
- checkboxes state doesn't propagate from children to parents.
- newly added nodes don't have their checkboxes in the appropriate states.
- the copy method doesn't test if the target directory is an empty string before copying.


But the 2 worst mistakes which make the whole program not functional are:
- 1st, in the method tvwExpand(): currentNode.Nodes.Clear( );
Deleting the subnodes each time we expand the parent node also delete the checkboxes, so when a node is collapsed and expanded again, all the checked/unchecked nodes are lost.
So are we supposed to never collapse a node? Then what's the purpose of using a TreeView? It makes the navigation impractical.
In fact, managing a TreeView is a bit more complex that what's explained in the book, and involves a bit more thoughts.
One way of doing would be to keep track of those expanded nodes, by using the node.Tag property and mark them as "visited" nodes.
Also there's no need to call GetSubDirectoryNodes() each time a node is expanded, depending on the recursive level.
With a recursive level of 2, each call to GetSubDirectoryNodes() potentially adds 3 level of depth to the TreeNodes.
Which means we can expand nodes on 2 levels before calling the function again.
We have to call the function one level higher in the tree than its deepest level, or the [+] sign won't show on directories.
A test like if (currentNode.Level % (MaxRecursLevel + 1) == MaxRecursLevel) would do the trick.
By doing that we never call the function twice for the same node, saving a lot of resource, and we also make the collapse/expand usefull again.

- 2nd, the GetFileList()/Copy() set of methods. I don't know what the author was thinking when he implemented those methods.
Using 2 foreach loops to retreive a list of FileInfo? It could be done in one clean and easy to understand loop, using only one list and one function.
Then the one big mistake is that the author is only relying on the treenode to retreive the files to copy.
It can't be done that way, especially when we load the nodes bits by bits.
The TreeView is just a partial and visual display of the files and directories on the drives (unless we load everything at once, which is unlikely to happen), but we cannot assume that the treeview and its associated treenodes contains and is aware of the files that we want.
The TreeView only "sees" the files at MaxRecursLevel + 1 and "grows" deeper only when we expand some nodes deep enough in the tree.
For exemple, if I check a directory at depth level 1, meaning that I want all of its containing files and never expand it, I won't be able to get the files that are at depth level 3 or 4 and beyond, because they were never displayed in the treeview and were never added to the treenodes.
So to make the Copy work, the GetFileList() method should retreive all the checked leaf nodes (files and directories), add the file nodes to the list and start a new recursive loop starting with the leaf directory nodes but using a FileSystemInfo.GetFileSystemInfo() this time to retreive the files and subdirectories directly on the drives.
(A checked leaf directory node always mean that it has never been expanded and that I want all the files that it contains.)

Anonymous  Jun 07, 2014 
Printed Page 442
First paragraph, first sentence

The first sentence on page 442 says:

"The Windows Forms techniques you learning in Chapter 18"

I think the author intended to say:

"The Windows Forms techniques you learned in Chapter 18"

Anonymous  Apr 29, 2010 
Printed Page 466
Example 19-7 source code

the names space is "PhotoCatalog". It should be the same as the namespace for the project.

Stephen Korow  Jan 21, 2010 
Printed Page 472
White House Presidents Image URL in code example

The URLs for the images have been changed and are different from both the book version and the downloadable example. Pay attention to the spelling of the URLs for images to the 8th, the 15th and the 19th presidents.

He Wang  Jul 15, 2009 
Printed Page 488
Example 20-1

Building the proposed example i get

Cannot implicitly convert type 'System.Data.DataSet.Tables[]' to 'System.Data.DataTable'

I am not sure where is the problem though.

Vyzikidis Stefanos  Dec 01, 2010 
Printed Page 567
1st paragraph or the Example 10-4 code

Exercise 10-4 asks for a method to initialize the chessboard array and a method to test whether a square is black or white. The sample solution ignores the word "method". The initialization and testing code are just part of the Run() method. Either the question or the sample code is wrong.

Anonymous  Jul 01, 2009 
Printed Page 601
top

Exercise 14-3 is about Stacks & Queues. Shouldn't the solution involve Pop & Dequeue? The solution in the book just iterates through the stack & queue with a foreach loop and ToString(essentially). I did this instead:

Console.Write("Clearing the animal Stack:");
int stackCount = myAnimalStack.Count; // can't use .Count in loop
for (int i = 0; i < stackCount; i++) // it drops by 1 with each Pop
{
Console.Write("\n(Pop): {0}", myAnimalStack.Pop());
}

Console.Write("\nClearing the animal Queue:");
int queueCount = myAnimalQueue.Count;
for (int i = 0; i < queueCount; i++)
{
Console.Write("\n(Dequeue): {0}", myAnimalQueue.Dequeue());
}

Anonymous  Aug 02, 2009 
Printed Page 621
Solution to Question 17-9

In the solution to question 17-9 it appears that instead of showing how you create delegated methods anonymously, it explains what an anonymous method is. Unless I misunderstand the question, an explanation and an example would seem like what the other actually intended. Or, either the question or answer is wrong (rather they do not match). It seems it should show something like this:

myDelegate.PhoneHasRung += delegate {...};

Sorry if I am incorrect or misunderstand about what was intended here.

Anonymous  Apr 28, 2010