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.

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
Printed Page 209
Before the last line of this page

In the method: internal void Add(SomeDataOriginator.Memento memento)
{
SaveState.Add(memento);
}

should read:

saveState.Add(memento);

Note: the variable saveState was previously declared at the line 2 of the class
MultiMementoCareTaker.

Page 530

RemoveAt method description

Add ( int index )

should read

RemoveAt ( int index )


Anonymous   
Printed Page 582
FindAllIllegalChars example

The invalidCharPos increments in the last else statment of the example is redudant and could
eventually make the routine miss one illegal character in the userEnteredPath parameter. The
invalidCharPos variable is already incremented by one when passed to the String.IndexOfAny method
at the beginning of the example. When the subsequent increment is made, one character is missed in
the next call to String.IndexOfAny.

I've used example in a routine that replace all illegal characters in a file name with undescores:

private string ReplaceAnyIllegalChars(string OutputFileName)
{
int invalidCharPos = -1;
bool endOfName = false;
bool foundIllegalChars = false;
string fileName = OutputFileName;

while (!endOfName)
{
invalidCharPos = fileName.IndexOfAny(Path.GetInvalidFileNameChars(), invalidCharPos + 1);
if (-1 == invalidCharPos)
{
endOfName = true;
}
else
{
foundIllegalChars = true;
fileName = fileName.Replace(OutputFileName[invalidCharPos], '_');
if (invalidCharPos >= fileName.Length - 1)
{
endOfName = true;
}
}
}

return fileName;
}

Anonymous