C# Cookbook by Stephen Teilhet, Jay Hilyard This errata page lists errors outstanding in the most recent printing. If you have technical questions or error reports, you can send them to booktech@oreilly.com. Please specify the printing date of your copy. This page was updated January 21, 2005. Here's a key to the markup: [page-number]: serious technical mistake {page-number}: minor technical mistake : important language/formatting problem (page-number): language change or minor formatting problem ?page-number?: reader question or request for clarification Confirmed errors: {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. [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 } }