PrintNumber ErrorLocation Error Correction DateAdded
1 pii First Printing March 2010 TBD 4/22/2011
1 pv-xiii Add (New in .NET 4) on all that apply in TOC fixed 4/22/2011
1 pvii Convert IEnumerable<string> to IEnumerable<object>
(Covariance) 149
Convert IComparer<Child> to IComparer<Parent>
(Contravariance) 150
Convert IEnumerable<Child> to IEnumerable<Parent>
(Covariance) 149
Convert IComparer<Parent> to IComparer<Child>
(Contravariance) 150
4/22/2011
1 pix Convert Colors Between RGB to HSV 331 Convert Colors Between RGB and HSV 331 4/22/2011
1 pxi Response to Timer Events on the UI Thread Respond to Timer Events on the UI Thread 4/22/2011
1 p3 Thankfully, the MSDN documentation for .NET (located at http://msdn.microsoft.com/
en-us/library/aa139615.aspx) is top-notch.
Thankfully, the MSDN documentation for .NET (located at http://msdn.microsoft.com/
en-us/library/) is top-notch.
4/22/2011
1 p11 Vertex3d a = new Vertex3d(0,0,1);
Vertex3d b = new Vertex3d(1,0,1);
Vertex3d a = new Vertex3d(0, 0, 1);
Vertex3d b = new Vertex3d(1, 0, 1);
4/22/2011
1 p11 this._x =x; this._x = x; 4/22/2011
1 p16 public class Base
{
Int32 _x;
public class Base
{
protected Int32 _x;
4/22/2011
1 p17 public class Derived public class Derived : Base 4/22/2011
1 p17 Overriding Non-virtual Methods and Properties Override Non-virtual Methods and Properties 4/22/2011
1 p32 return string.Format(“Type: {0}, Value: {1}”, arg.GetType(), value);

alignment corrected
fixed 4/22/2011
1 p38 PropertyChanged(this, new
PropertyChangedEventArgs(propertyName));

alignment corrected
fixed 4/22/2011
1 p46 Scenario/Problem: You need to store data in a class.
Scenario/Problem: You need to store data in a class.
4/22/2011
1 p50 This is actually just another form of object initialization, which was described in Chapter 1, “Type Fundamentals.” This is just another form of object initialization, which was described in Chapter 1, “Type Fundamentals.” 4/22/2011
1 p65 Because ArgumentNullException is a type of ArgumentException, and ArgumentException is first in the catch list, it will be called. Because ArgumentNullException is a type of ArgumentException, and ArgumentException is first in the catch list, the compiler will give you an error. 4/22/2011
1 p93 This runs in time proportion to the number of 1 bits set in number. This runs in time proportional to the number of 1 bits set in number. 4/22/2011
1 p94 Scenario/Problem: In many graphical editors, a common feature is to restrict mouse positions to gridlines. This makes the user’s job easier because they don’t have to make ultra-precise mouse movements when editing shapes. For example, if the mouse were at (104, 96) and you wanted the values snapped to a 5-by-5 pixel grid, you could change them to (105, 95).

Wrong font used.
fixed 4/22/2011
1 p117 The first two conditions are handled by the static method String.IsNullOrEmpty(), which has existed in .Net for a while.
.Net 4 adds String.IsNullOrWhitespace(), which also handles condition 3.
The first two conditions are handled by the static method String.IsNullOrEmpty(), which has existed in .NET for a while.
.NET 4 adds String.IsNullOrWhitespace(), which also handles condition 3.
4/22/2011
1 p132 Scenario/Problem: You need an advanced text search where you can find patterns. Scenario/Problem: You need an advanced text search to find patterns. 4/22/2011
1 p139 Convert IComparer<Child> to IComparer<Parent> (Contravariance) Convert IComparer<Parent> to IComparer<Child> (Contravariance) 4/22/2011
1 p149 Convert IEnumerable<string> to IEnumerable<object> (Covariance)
Scenario/Problem: You want to pass a generic collection to a method that only accepts IEnumerable<object> (or some other parent of your type). For example, suppose you want to do this:
interface IShape
{
void Draw();
}

interface IRectangle : IShape
{
void HitTest();
}

class Program
{
static void Main(string[] args)
{
List<IRectangle> rects = new List<IRectangle>();
Convert IEnumerable<Child> to IEnumerable<Parent> (Covariance)
Scenario/Problem: You want to pass a generic collection to a method that only accepts IEnumerable<object> (or some other parent of your type). For example, suppose you want to do this:
interface Shape
{
void Draw();
}

interface Rectangle : Shape
{
void HitTest();
}

class Program
{
static void Main(string[] args)
{
List<Rectangle> rects = new List<Rectangle>();
4/22/2011
1 p150 static void DrawShapes(IEnumerable<IShape> shapes)
{
foreach (IShape shape in shapes)
static void DrawShapes(IEnumerable<Shape> shapes)
{
foreach (Shape shape in shapes)
4/22/2011
1 p150 Solution: In .NET 4, covariance and contravariance are supported on interfaces and delegates, so the preceding code will work as-is. This is known as covariance. It only works because IEnumerable is declared as IEnumerable<out T>, which means that you cannot give T as an input to any method on IEnumerable. This rule implies that any output of this collection can also be treated as a collection of the parent class of T, which makes sense since iterating over IRectangle is equivalent to iterating over IShape.
On the other hand, imagine if we had another type of shape, ICircle, which is also derived from IShape. The collection should not be treated as a collection of IShape for the purposes of insertion, because this would imply you could also add an ICircle, which is not the case, since it’s really a collection of IRectangle objects. That’s why T is declared as an out parameter: It only works when reading values out of the collection, not putting them in, and it explains why covariance can work in the preceding code example.
Solution: In .NET 4, covariance and contravariance are supported on interfaces and delegates, so the preceding code will work as-is. This is known as covariance. It only works because IEnumerable is declared as IEnumerable<out T>, which means that you cannot give T as an input to any method on IEnumerable. This rule implies that this collection can also be treated as a collection of the parent class of T, when reading from it which makes sense since iterating over Rectangle is equivalent to iterating over IShape.
On the other hand, imagine if we had another type of shape, Circle, which is also derived from Shape. The collection should not be treated as a collection of Shape for the purposes of insertion, because this would imply you could also add an Circle, which is not the case, since it’s really a collection of Rectangle objects. That’s why T is declared as an out parameter: It only works when reading values out of the collection, not putting them in, and it explains why covariance can work in the preceding code example.
4/22/2011
1 p150 Convert IComparer<Child> to IComparer<Parent> (Contravariance) Convert IComparer<Parent> to IComparer<Child> (Contravariance) 4/22/2011
1 p156 Note that only the basic Array type cannot grow beyond its initial size. All the others will manage their internal storage such that objects can be added to it indefinitely (limited by memory, of course). Note that only the basic Array type cannot grow beyond its initial size. All the others will manage their internal storage such that objects can be added to it indefinitely (limited by memory, of course).

The Big O notation indicates the performance, proportional to the size of the collection. O(1) means the time B constant.
4/22/2011
1 p166 Console.WriteLine();
Console.Write(“In-order: “);
foreach (int val in tree.InOrder)
Console.WriteLine();
Console.Write(“In-order: “);
//Since InOrder is default, we could have
//said foreach (int val in tree)
foreach (int val in tree.InOrder)
4/22/2011
1 p179 You should consider this a best practice that you should always follow whenever possible. Consider this a best practice that you should always follow whenever possible. 4/25/2011
1 p182 * output file streamand then write bytes to it,
* those bytes will be compressed.
*/
using (Stream inFileStream =
File.Open(sourceFile, FileMode.Open,
FileAccess.Read, FileShare.Read))
using (Stream outFileStream =
File.Open(destFile, FileMode.Create,
FileAccess.Write, FileShare.None))
* output file streama nd then write bytes to it,
* those bytes will be compressed.
*/
using (Stream inFileStream =
File.Open(sourceFile, FileMode.Open,
FileAccess.Read, FileShare.Read))
using (Stream outFileStream =
File.Open(destFile, FileMode.Create,
FileAccess.Write, FileShare.None))
4/25/2011
1 p194 Solution: The easy way to allow a type to be serialized is to just put the attribute [Serializable] in front of the type definition. .NET provides three built-in serialization formatters: SOAP , binary, and XML. XML serialization is handled a little differently and will be discussed in its own chapter (see Chapter 14, “XML”).

The comma after SOAP is too close.
fixed 4/25/2011
1 p213 Scenario/Problem: You need to download a file from an FTP site. Scenario/Problem: You need to upload a file to an FTP site. 4/26/2011
1 p247 However, do your due diligence: Sometimes there are laws that require certain types of data to be deleted after a certain amount of time. However, do your due diligence: Sometimes there are laws that require certain types of data to be deleted after some amount of time. 4/26/2011
1 p247 Solution: Stores procedures are something like methods stored on the server, and .NET supports them by settings the CommandType on the SqlCommand object. Solution: Stored procedures are something like methods stored on the server, and .NET supports them by settings the CommandType on the SqlCommand object. 4/26/2011
1 p259 This will create the Book and BookEntities object for you. The following sections will demonstrate how to use them. This will create the Book and BookEntities class for you. The following sections will demonstrate how to use them. 4/26/2011
1 p329 Convert Colors Between RGB to HSV Convert Colors Between RGB and HSV 4/26/2011
1 p337 new Point (10, 50) new Point(10, 50) 4/26/2011
1 p345 e.Graphics.InterpolationMode =_InterpolationMode.Bicubic; e.Graphics.InterpolationMode = InterpolationMode.Bicubic; 4/26/2011
1 p418 Solution: Sites such as these have moveable, componentized layouts. It is quite easy to add this type of feature into your own application by using ASP.NET.’s web parts feature. Solution: It is quite easy to add this type of feature into your own application by using ASP.NET.’s web parts feature. 4/26/2011
1 p433 Scenario/Problem: You must decide where users’ session information should be stored, especially if the default of in-process will not work for you.

This becomes a more important issue when your site is large enough to need multiple web servers or has enough users that their session information has significant memory requirements.
2nd sentence should be part of the Scenario/Problem and shaded.

Fixed.
4/26/2011
1 p437 //return a viewn named Index //return a view named Index 4/26/2011
1 p443 Response to Timer Events on the UI Thread Respond to Timer Events on the UI Thread 4/26/2011
1 p451 Response to Timer Events on the UI Thread Respond to Timer Events on the UI Thread 4/26/2011
1 p570 3. In the project properties, go to the Sliverlight tab, and click the Assembly Information… button. 3. In the project properties, go to the Silverlight tab, and click the Assembly Information… button. 4/26/2011
1 p581 1. Create a log source. This is typically your application. 1. Create a log source. This is typically your application name. 4/26/2011
1 p628 SysInternals (now owned by Microsoft) produced some gems of utilities, and the two I use most are Process Explorer and Process Monitor. SysInternals (now owned by Microsoft) produces some gems of utilities, and the two I use most are Process Explorer and Process Monitor. 4/26/2011
1 p631 LINQPad also lets you just test out quick code snippets to see the results, without having to create dummy test project. LINQPad also lets you just test out quick code snippets to see the results, without having to create a dummy test project. 4/26/2011