Errata

C# Cookbook

Errata for C# Cookbook

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. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

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

Version Location Description Submitted By Date submitted Date corrected
Printed
Page 13
Discussion for 1.10, first sentence

Static.Round

NOW READS:
Math.Round

Anonymous    Jul 01, 2004
Printed
Page 14
Sections 1.11 and 1.12

The discussions of each solution previously had their respective formulas transposed.

Therefore, the formula in the Discussion of section 1.11 NOW READS:
TempFahrenheit = ((9/5) * TempCelsius) + 32

And the formula in the Discussion of section 1.12 NOW READS:
TempCelsius = (5/9) * (TempFahrenheit -32)

Anonymous    Jul 01, 2004
Printed
Page 52
first paragraph of the discussion

Any value larger than 127 is converted to the ? character.

Should read:

Any value larger than 127 will be AND'ed with the value 127 and the
resulting character value will be displayed in the string. For example, if
the byte array contains the value 200, this value will be converted to 72,
and the character equivalent of 72 ('H') will be displayed.

Anonymous   
Printed
Page 111
next to the tip icon

The XOR(~) operator NOW READS XOR(^) operator

Anonymous    Jul 01, 2004
Printed
Page 235
Last code solution

The solution code:

if ((lang | (Language.CSharp | Language.VBNET)) ==
(Language.CSharp | Language.VBNET))
{
// lang contains only the Language.CSharp and Language.VBNET
}

There is one bug in this code due to the fact that a developer could set the
lang variable to any integer value. Basically, the code works for any value
for lang that is greater than zero. So, the following is true:

For lang values of 1 (CSharp), 2 (VBNET), or 3 (CSharp | VBNET) the
expression evaluates to true, which it does.
For lang values of 4 (VB6) or greater (CSharp | VBNET | VB6) the
expression evaluates to false, which it does.
However,
For a lang value of 0 (not defined in the Language enum) the
expression SHOULD (in this case) evalutate to false, which it does not.

If the Language enumeration were written as:
enum Language
{
ALL=0, CSharp=1, VBNET=2, ...
}
Then the if statement would evaluate correctly, but who writes enumerations
like this. Usually the ALL enumeration value is equal to all the relevent
bits turned on (e.g. ALL=16). So to fix this problem we can add an extra if
statement to make sure that the enumeration value contained in the lang
variable is greater than zero, as shown here:

if (lang > 0)
{
if ((lang | (Language.CSharp | Language.VBNET)) ==
(Language.CSharp | Language.VBNET))
{
// lang contains only the Language.CSharp and Language.VBNET
}
}

Anonymous