Tonight I finished reading C# in Depth: What you need to master C# 2 and 3 by Jon Skeet
This was an amazing book, and definitely offers a great in depth look at the C# language. Most importantly it answered a lot of my questions about elements introduced in C# 3.0, and taught me things I didn’t know about C# 1.0. If you’re looking for information on the following items, then this book is definitely for you.
ExpressionIQueryableIQueryProvider- Lamba’s
- Type Inferencing
Here are a few gems that I picked from this book.
Delegates
“You rarely see an explicit call to Delegate.Combine in C# code - usually the + and += operators are used.”
var x = new EventHandler(delegate { });
var y = new EventHandler(delegate { });
x += y;
x = x + y;// same as above
x = (EventHandler) Delegate.Combine(x, y);// same as above
Static vs Dynamic Typing
“C# is statically typed: each variable is of a particular type, and that type is known at compile time. The alternate to static typing is dynamic typing, which can take a variety of guises. “
Explicit vs. Implicit Typing
“The distinction between explicit typing and implicit typing is only relevant in statically typed languages. With explicitly typing, the type of every variable must be explicitly stated in the declaration. Implicit typing allows the compiler to infer the type of the variable based on its use.”
Covariant vs. Incovariant
object[] stuff = new string[]{"blah"}; // valid and is an example of covariance
List<object> more_stuff = new List<string>(); // invalid and is an example of incovariance
Fluent Interfaces
Here’s an example of a fluent interface for building menu’s that I’ve been playing with.
CreateA.MenuItem()
.Named("&Close")
.BelongsTo(MenuGroups.File)
.CanBeClickedWhen(m => task.IsThereAProtocolSelected())
.WhenClickedExecute(closeCommand)
.Build();
Readability
“When it comes to getting the broad sweep of code, what is required is ‘readability of results’ - I want to know what the code does, but I don’t care how it does it right now.”
There’s a lot of information on IQueryables, Expression Trees, and other goodness in this book.
This is a great book and definitely worth reading, especially if you’re as interested in the C# language as I am.