Microsoft KB Archive/905044

= Programming Microsoft Visual C# 2005: The Language comments and corrections =

Article ID: 905044

Article Last Modified on 11/15/2007

-

APPLIES TO


 * Programming Microsoft Visual C# 2005: The Language, ISBN 0-7356-2181-0

-



SUMMARY
This article contains comments, corrections, and information about known errors relating to the Microsoft Press book Programming Microsoft Visual C# 2005: The Language, ISBN 0-7356-2181-0.

The following topics are covered:


 * CD-ROM: Incorrect variable name used in \Chapter 2\prop_error\person1.cs and \Chapter 2\prop_error\person2.cs sample files
 * CD-ROM: Updated code samples for Refactoring Walkthrough in chapter 4 available for download
 * Page 11: Missing &quot;)&quot; and &quot;;&quot; in code sample
 * Page 15: Error should be Pragma
 * Page 21: Incorrect Sample code for Postfix Increment and Postfix Decrement in Table 1-4
 * Page 24: Error in Conditional Operator example
 * Page 37: Variable name error in code sample
 * Page 37: variablea referenced in place of variable2
 * Page 40: Error in switch statement explanation
 * Page 48: Incorrect variable name used in code sample
 * Page 66: Error in description of constructor output
 * Page 68: Destructor description missing the word &quot;name&quot;
 * Page 71: Term &quot;backing&quot; used in place of the term &quot;data&quot;
 * Page 80: Technical error in comparison of locala and localb variables
 * Page 80: Example variable has the wrong type
 * Page 150: Derived class referenced in place of base class
 * Page 150: Incorrect instruction for creating a derived class relationship
 * Page 187: Term &quot;multirectangle&quot; used in place of &quot;multidimensional&quot;
 * Page 201: Array.CreateInstance Method code example is partially incorrect
 * Page 206: IComparer should be IComparable
 * Pages 235-236: Technical errors in code sample
 * Page 281: The term &quot;an enumerator&quot; is used in place of &quot;enumerated&quot;
 * Page 281: Incorrect variable name used in the code sample
 * Pages 386-387: Incorrect code sample included



CD-ROM: Incorrect variable name used in \Chapter 2\prop_error\person1.cs and \Chapter 2\prop_error\person2.cs sample files
The ninth line of both the \Chapter 2\prop_error\person1.cs and \Chapter 2\prop_error\person2.cs sample files reads:

if(age<0 || age>120) {

It should read:

if(value<0 || value>120) {

CD-ROM: Updated code samples for Refactoring Walkthrough in chapter 4 available for download
Updated code samples are available for the Refactoring Walkthrough in chapter 4. The following file is available for download from the Microsoft Download Center:

Airline.exe

For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:

119591 How to Obtain Microsoft Support Files from Online Services

Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.

Page 11: Missing &quot;)&quot; and &quot;;&quot; in code sample
On Page 11, the 12th line of the first code sample reads:

Console.WriteLine(objGreeting.French

It should read:

Console.WriteLine(objGreeting.French);

Page 15: Error should be Pragma
On page 15, midway down the page, it reads:

&quot;The #pragma directive enables or disables standard compilation warnings.

Error directives:


 * 1) error warning disable warning_list


 * 1) error warning restore warning_list &quot;

It should read:

&quot;Pragma directives:


 * 1) pragma warning disable warning_list


 * 1) pragma warning restore warning_list &quot;

Page 21: Incorrect Sample code for Postfix Increment and Postfix Decrement in Table 1-4
On page 21, the Postfix Increment and Postfix Decrement rows of Table 1-4 read:

Postfix Increment  ++  variable --; 10; 10 Postfix Decrement  --  variable ++; 11

They should read:

Postfix Increment  ++  variable ++; 11 Postfix Decrement  --  variable --; 10

Page 24: Error in Conditional Operator example
On page 24, under Ternary operators, the Conditional Operator example currently reads:

boolean_expression:truth_statement?false_statement

It should read:

boolean_expression?truth_statement:false_statement

Page 37: Variable name error in code sample
On page 37, the second code sample in the &quot;Nullable Types&quot; section reads:

double? variablea=null;

It should read:

double? variable1=null;

Page 37: variablea referenced in place of variable2
On page 37, the second to last sentence of the final paragraph reads:

&quot;This code sets the default value for variablea to zero.&quot;

It should read:

&quot;This code sets the default value for variable2 to zero.&quot;

Page 40: Error in switch statement explanation
On page 40, below the sample Switch statement code, the sixth sentence in the paragraph reads:

&quot;If switch label matches the switch expresssion...&quot;

It should read:

&quot;If no switch label matches the switch expression...&quot;

Page 48: Incorrect variable name used in code sample
On page 48, the ninth and tenth lines of the code sample read:

Employee Jim=new Employee; Fred.name=&quot;Wilson, Jim&quot;;

They should read:

Employee Fred=new Employee; Fred.name=&quot;Wilson, Fred&quot;;

Page 66: Error in description of constructor output
On page 66, the fourth sentence of the paragraph immediately following the bulletted list reads:

&quot;The static constructor is stubbed to output a method.&quot;

It should read:

&quot;The static constructor is stubbed to output a message.&quot;

Page 68: Destructor description missing the word &quot;name&quot;
On page 68, the fifth sentence of the Destructors section reads:

&quot;Like a constructor, the destructor has the same as the class...&quot;

It should read:

&quot;Like a constructor, the destructor has the same name as the class... &quot;

Page 71: Term &quot;backing&quot; used in place of the term &quot;data&quot;
On page 71, the first line currently reads:

&quot;public, whereas the backing store is private.&quot;

This should read:

&quot;public, whereas the data store is private. &quot;

Page 80: Technical error in comparison of locala and localb variables
On page 80, the fourth and fifth sentences of the second paragraph in the &quot;Identity versus Equivalence&quot; section read:

&quot;The variables locala and localb are not equivalent. They have the same values but are stored at different locations on the stack:&quot;

They should read:

&quot;The variables locala and localb are neither equivalent nor identical. They have different values and are stored at different locations on the stack:&quot;

Page 80: Example variable has the wrong type
On page 80, the third line of the first code sample in the &quot;Identity versus Equivalence&quot; section reads:

double localc=5;

It should read:

int localc=5;

Page 150: Derived class referenced in place of base class
On page 150, the last sentence of the first paragraph reads:

&quot;This both creates the inheritance relationship and adds the derived class to the class diagram.&quot;

It should read:

&quot;This both creates the inheritance relationship and adds the base class to the class diagram.&quot;

Page 150: Incorrect instruction for creating a derived class relationship
On page 150, the third sentence on the page reads:

&quot;Drag the inheritance line from the base class to the derived class.&quot;

It should read:

&quot;Drag the inheritance line from the derived class to the base class.&quot;

Page 187: Term &quot;multirectangle&quot; used in place of &quot;multidimensional&quot;
On page 187, the fourth sentence of the first paragraph reads:

&quot;Multirectangle arrays are rectangular and consist of rows and columns.&quot;

It should read:

&quot;Multidimensional arrays are rectangular and consist of rows and columns.&quot;

Page 201: Array.CreateInstance Method code example is partially incorrect
On page 201, the code example contains incorrect array offsets. The correction starts on line 7.

Change: Assembly executing=Assembly.GetExecutingAssembly; Type t=executing.GetType(argv[0]); Array zArray=Array.CreateInstance(   t, argv.Length-2); for(int count=2;count<argv.Length;++count) { System.Object obj=Activator.CreateInstance(t, new object[] {       argv[count]}); zArray.SetValue(obj, count-2); } foreach(object item in zArray) { MethodInfo m=t.GetMethod(argv[1]); m.Invoke(item, null); }

To: Assembly executing = Assembly.GetExecutingAssembly; Type t = executing.GetType(argv[1]); Array zArray = Array.CreateInstance(   t, argv.Length - 3); for (int count = 3; count < argv.Length; ++count) { System.Object obj = Activator.CreateInstance(t, new object[] {                   argv[count]}); zArray.SetValue(obj, count - 3); } foreach (object item in zArray) { MethodInfo m = t.GetMethod(argv[2]); m.Invoke(item, null); }

Page 206: IComparer should be IComparable
On page 206, the 15th line down in the second code example on the page uses an incorrect interface.

Change: public class XClass: IComparer {

To: public class XClass: IComparable {

Pages 235-236: Technical errors in code sample
On pages 235-236, the code sample reads:

using System;

namespace Donis.CSharpBook{ public class Starter{ public static void Main{ StackInt stack=new StackInt(5); stack.Push(10); stack.Push(15); Console.WriteLine(&quot;Pushed 3 values&quot;); stack.ListItems; stack.Pop; Console.WriteLine(&quot;Popped 1 value&quot;); stack.ListItems; }   }

public class StackInt {

public StackInt(int firstItem) { list=new int[1] {firstItem}; }

public int Pop { if(top!=0) { return list[--top]; }           throw new Exception(&quot;Stack empty&quot;); }

public void Push(int topitem) { ++top; if(top==list.Length) { int [] temp=new int[top+1]; Array.Copy(list, temp, top); list=temp    ; }           list[top]=topitem; }

public void ListItems { for(int item=0;item<=top;++item) { Console.WriteLine(list[item]); }       }

private int [] list; private int top=0; }

}

It should read:

using System;

namespace Donis.CSharpBook{ public class Starter{ public static void Main{ StackInt stack=new StackInt(5); stack.Push(10); stack.Push(15); Console.WriteLine(&quot;Pushed 3 values&quot;); stack.ListItems; stack.Pop; Console.WriteLine(&quot;Popped 1 value&quot;); stack.ListItems; }   }

public class StackInt {

public StackInt(int firstItem) { list=new int[1] {firstItem}; top++; }

public int Pop { if(top!=(-1)) { return list[top--]; //was list[--top] }           throw new Exception(&quot;Stack empty&quot;); }

public void Push(int topitem) { ++top; if(top==list.Length) { int [] temp=new int[top+1]; Array.Copy(list, temp, top); list=temp    ; }           list[top]=topitem; }

public void ListItems { for(int item=0;item<=top;++item) { Console.WriteLine(list[item]); }       }

private int [] list; private int top=(-1); }

}

Page 281: The term &quot;an enumerator&quot; is used in place of &quot;enumerated&quot;
On page 281, the fourth sentence of the first paragraph reads:

&quot;In Main, the collection is an enumerator in a generic and nongeneric manner.&quot;

It should read:

&quot;In Main, the collection is enumerated in a generic and nongeneric manner.&quot;

Page 281: Incorrect variable name used in the code sample
On page 281, the 14th line of the code sample reads:

foreach(int number in generic) {

It should read:

foreach(int number in simple) {

Pages 386-387: Incorrect code sample included
On pages 386-387, the sample code in the GetGenericArguments section reads:

using System;

namespace Donis.CSharpBook {

class ZClass { public void FunctionA(K argk, V argv) { }   }

class Starter { public static void Main { ZClass obj=new ZClass; ZClass obj2=new ZClass;

Type closedType=obj.GetType; Type openType=closedType.GetGenericTypeDefinition;

Type closedType2=obj2.GetType; Type openType2=closedType2.GetGenericTypeDefinition;

Console.WriteLine(openType.ToString); Console.WriteLine(openType2.ToString); }   } }

It should read:

using System; using System.Reflection;

namespace Donis.CSharpBook{

public class ZClass {

public void MethodA{ }

public K membera; public V memberb; }

class Starter{

static void Main{ Type openType=typeof(ZClass<,>); foreach(Type parameter in openType.GetGenericArguments) { Console.WriteLine(parameter.ToString); }           Type closedType=typeof(ZClass); foreach(Type parameter in closedType.GetGenericArguments) { Console.WriteLine(parameter.ToString); }           MethodInfo method=openType.GetMethod(&quot;MethodA&quot;); foreach(Type parameter in method.GetGenericArguments) { Console.WriteLine(parameter.Name); }       }    } }

Microsoft Press is committed to providing informative and accurate books. All comments and corrections listed above are ready for inclusion in future printings of this book. If you have a later printing of this book, it may already contain most or all of the above corrections.

The print number of the book is located on the copyright page in the form of a string of numbers. For example: &quot;2 3 4 5 6 7 8 0 QWT 9 8 76 5 4&quot;. The first number in the string is the the print number. In this example, the print number is 2.

Additional query words: 0-7356-2181-0 978-0-7356-2181-7

Keywords: kbinfo kbdocfix kbdocerr KB905044

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.