C# in Depth: Chapters 6 and 7 now in MEAP

Chapters 6 and 7 have now been included in the Manning Early Access Program. That means that the whole of the C# 2 part of the book is now available. Marc Gravell has been picking holes in it on the forum (and I mean that in a very positive way – it’s great to have more eyes running over it). Can you find more errors? Here’s a rundown of chapters 6 and 7:   Chapter 6: Implementing iterators the easy way In C# 1, it was a pain to implement IEnumerable. C# 2 makes it easy with iterator blocks, and … Continue reading C# in Depth: Chapters 6 and 7 now in MEAP

Fun with captured variables

  I’m currently writing about readability, and discussing deferred parameter evaluation in LINQ on the C# newsgroup. It’s led me to come up with quite an evil application of captured variables. Consider this C# 3 code: using System;using System.Linq;public class Test{ static void Main() { int max = int.MinValue; int[] values = { 0, 5, 2, 3, 8, 4, -1, 10, 12, 8, 100 }; var query = from value in values where value > max select (max=value); foreach (int value in query) { Console.WriteLine(value); } }} The max and values variables are easy enough to understand, and the foreach loop … Continue reading Fun with captured variables

LINQ to Silliness: Generating a Mandelbrot with parallel potential

I’ve been writing about LINQ recently, and in particular I’ve written a small amount about Parallel LINQ. (Don’t get excited – it’s only about a page, just to mention it as a sort of “meta-provider” for LINQ.) I was wondering what to use to demonstrate it – what general task can we perform which could take a lot of CPU? Well, I used to be quite into fractals, and I’ve written Mandelbrot set generators in various languages. I hadn’t done it in C# before now, however. Calculating the colour of each pixel is completely independent of all the other pixels … Continue reading LINQ to Silliness: Generating a Mandelbrot with parallel potential

Yeehaa! Framework source code, here we come!

It’s just been announced on Scott Guthrie’s blog that Visual Studio 2008 will allow debugging into the source code for the .NET framework – at least for some areas. I’ve wanted this to happen for a long time, and blogged about it before now – but I didn’t honestly expect it to happen, at least not for a long time. This is a fabulous move, and one which MS should be commended for. I’m sure many people will spend a long time discussing whether the licence can be described as “open” (you can’t copy the code or recompile it) but to … Continue reading Yeehaa! Framework source code, here we come!