Effective C# is a great book.

If like me you have be coding C# for a while (in my case nearly two years) and are beginning to feel that you have C# completely sussed then this is the perfect book for you. Thanks to this book I now know that there are many more subtlies hidden away in C# and the .NET framework than I first thought.

The book is subtitled “50 Specific Ways to Improve Your C#” and is separated into 50 topics of varying length. The title is slightly misleading though, as many of the topics apply to coding in any .NET language rather than just C#.

I have read at least half a dozen books on C#/.NET and none of them did a very good job of explaining the full implications of the differences between value and reference types. In this book Bill Wagner clearly details the differences between the two and exactly what that means for you class and structure design.

Bill’s descriptions of the issues are very clear, even when he is talking about things as potentially confusing as the relationships between ReferenceEquals(), static Equals(), instance Equals(), operator== and the dreaded GetHashCode().

As an example of one of the subtlies that the book covers, take a look at this code:

int [] foo = new int[100];

// Loop 1:
foreach (int i in foo)

// Loop 2:
for (int index = 0; index < foo.Length; index++)

// Loop 3:
int len = foo.Length;
for (int index = 0; index < len; index++)

So, which loop do you think it fastest? Loop 3 you say?

Nope, the fastest is Loop 1 and Loop 3 is in fact the slowest. To find out why you’ll have to read the book ;)

If you think that you know all there is to know about C# then buy this book…