Microsoft KB Archive/905044

From BetaArchive Wiki
Knowledge Base


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 ")" and ";" 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 "name"
  • Page 71: Term "backing" used in place of the term "data"
  • 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 "multirectangle" used in place of "multidimensional"
  • 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 "an enumerator" is used in place of "enumerated"
  • Page 281: Incorrect variable name used in the code sample
  • Pages 386-387: Incorrect code sample included


MORE INFORMATION


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 ")" and ";" 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:

"The #pragma directive enables or disables standard compilation warnings.

Error directives:

  1. error warning disable warning_list
  2. error warning restore warning_list "


It should read:

"Pragma directives:

  1. pragma warning disable warning_list
  2. pragma warning restore warning_list "


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 "Nullable Types" 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:

"This code sets the default value for variablea to zero."

It should read:

"This code sets the default value for variable2 to zero."

Page 40: Error in switch statement explanation

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

"If switch label matches the switch expresssion..."

It should read:

"If no switch label matches the switch expression..."

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="Wilson, Jim";


They should read:

Employee Fred=new Employee();
Fred.name="Wilson, Fred";



Page 66: Error in description of constructor output

On page 66, the fourth sentence of the paragraph immediately following the bulletted list reads:

"The static constructor is stubbed to output a method."

It should read:

"The static constructor is stubbed to output a message."

Page 68: Destructor description missing the word "name"

On page 68, the fifth sentence of the Destructors section reads:

"Like a constructor, the destructor has the same as the class..."

It should read:

"Like a constructor, the destructor has the same name as the class... "

Page 71: Term "backing" used in place of the term "data"

On page 71, the first line currently reads:

"public, whereas the backing store is private."

This should read:

"public, whereas the data store is private. "

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 "Identity versus Equivalence" section read:

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

They should read:

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

Page 80: Example variable has the wrong type

On page 80, the third line of the first code sample in the "Identity versus Equivalence" 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:

"This both creates the inheritance relationship and adds the derived class to the class diagram."

It should read:

"This both creates the inheritance relationship and adds the base class to the class diagram."

Page 150: Incorrect instruction for creating a derived class relationship

On page 150, the third sentence on the page reads:

"Drag the inheritance line from the base class to the derived class."

It should read:

"Drag the inheritance line from the derived class to the base class."

Page 187: Term "multirectangle" used in place of "multidimensional"

On page 187, the fourth sentence of the first paragraph reads:

"Multirectangle arrays are rectangular and consist of rows and columns."

It should read:

"Multidimensional arrays are rectangular and consist of rows and columns."

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("Pushed 3 values");
            stack.ListItems();
            stack.Pop();
            Console.WriteLine("Popped 1 value");
            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("Stack empty");
        }

        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("Pushed 3 values");
            stack.ListItems();
            stack.Pop();
            Console.WriteLine("Popped 1 value");
            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("Stack empty");
        }

        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 "an enumerator" is used in place of "enumerated"

On page 281, the fourth sentence of the first paragraph reads:

"In Main, the collection is an enumerator in a generic and nongeneric manner."

It should read:

"In Main, the collection is enumerated in a generic and nongeneric manner."

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<K,V> {
        public void FunctionA(K argk, V argv) {
        }
    }

    class Starter {
        public static void Main() {
            ZClass<int, decimal> obj=new ZClass<int, decimal>();
            ZClass<string, float> obj2=new ZClass<string, float>();

            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<K, V> {

        public void MethodA<A,B>(){
        }

    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<int,string>);
            foreach(Type parameter in closedType.GetGenericArguments()) {
                Console.WriteLine(parameter.ToString()); 
            }
            MethodInfo method=openType.GetMethod("MethodA");
            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: "2 3 4 5 6 7 8 0 QWT 9 8 76 5 4". 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