Thought for the Dazed

I've had to give up that Distance Learning course as I was having trouble seeing the teacher.

Flickr
www.flickr.com
RobMiles' items Go to RobMiles' photostream
Twitter
C# Yellow Book

Search entire site
Friday
Apr082011

C# Yield Return Fun

public static IEnumerable YieldFun()
{
    yield return 1;
    yield return 2;
    yield return 3;
}

static void Main(string[] args)
{
    foreach (int i in YieldFun())
    {
        Console.WriteLine(i);
    }
}

If you can tell me what the code above does, you understand how yield return works. If you can’t, read on……

In a C# program you can mark things as implementing the IEnumerable interface (to use this you need to have a using System.Collections; at the top of your program). This means the thing can be enumerated,  i.e. it means that I can get a succession of objects from it.

The best way to work through something that can be enumerated is by using the foreach construction, as shown above. You’ve probably seen foreach when you’ve worked through items in a collection such as a List or an array.  In the above code we are using foreach to work through the enumerable results that the YieldFun method returns. 

The code inside YieldFun looks a bit scary. The yield return keyword combination is followed by the thing that you want to send back for this iteration. In this case I’m just returning a different number each time. What happens when the yield return is reached is that the method stops at that point, returns the result and then, when the foreach asks for the next value, the method wakes up and continues at the next statement. The result of the program is simply the sequence:

1
2
3

If you want to programmatically supply a sequence of items to a consumer then this is  a great way to do it. 

Friday
Apr082011

The Rob Miles Roadshow

Next week I’m doing a Mix session all about game development in XNA, stay tuned for some brand new examples and sample code, but unfortunately no new jokes. I’ve just found out that I’m also doing Ask the Experts on Tuesday evening starting at 6:00 pm  (and for once I’m not going to be doing the asking).  They are using a “speed dating” arrangement where we meet up with a bunch of folks for 20 minute slots where we get over the gist of what we are at Mix for. I’ll be doing Windows Phone games (of course) and I’d love to meet you if you come along. Strange this, nothing for years and then two sessions of speed dating in a matter of a weeks.

image

If you are lucky enough to have a Windows Phone you can download the official Mix application which is great. And also mentions me. Search the marketplace for “Mix 11”.

The “Rob Miles Roadshow”™ then rumbles on to TechDays later this month. They also have a really good Windows Phone application too, although this one works best if you can speak Dutch. Search the marketplace for “Techdays”.

DevDays Speaker

I’m doing a session on Windows Phone games, another on the .NET Micro Framework and a third (deep breath) where I’m going to be talking about Windows Phone development in rhyme, just for Geek Night. And I’m also making an appearance at one of the keynotes too. Now, if that’s not a reason to buy a new pair of jeans, I don’t know what is… Find out more here.

Thursday
Apr072011

Prizes and Rewards with Windows Phone

image

There has never been a better time to be a Windows Phone developer. If you are a UK student you can take part in a Student Competition where you can win prizes just by submitting applications to the Marketplace. Since you can also sell these applications, and it costs you nothing to join the Marketplace if you register via DreamSpark this seems like a pretty good deal. Find out more here.

image

If you are old like me and therefore no longer a student you can instead sign up for the Think.Dev rewards programme and get prizes and rewards for submitting apps. This is open to all Windows Phone developers in the UK and you get stuff for just turning up and submitting apps. I might even win a prize for Cheese Lander (although this is probably unlikely). Sign up here.

Wednesday
Apr062011

Headphone wires aren’t what they use to be

Wires
All I have to do now is solder them onto a plug. Yeah, right.

My lovely (and so expensive I never told number one wife I bought them) Ultimate Ears headphones have broken. The wire that goes into the plug has failed on one of the connections. Being a chap who’s not afraid of hardware (perhaps because I don’t know that much about it) I was happy to get a new plug and solder it on. That is, until I saw what passes for wire these days.

In the Olden Days ™ headphones were wired with the next thing down from mains cable, which could be dismantled and worked on with industrial scale tools. My old Sony phones were much tougher too. They even survived a trip around the robot vacuum, which took a fancy to them one day.

Nowadays, with fancy “litz” cables and stuff it looks like it is pretty much impossible to mend the darned things. And they aren’t even heavy enough to serve as a decent paperweight.

Tuesday
Apr052011

Bulgarian Mystery

Image Instructions

I picked up this sticker thing from a stand in Bulgaria last week. I’ve no idea what the instructions say. Any ideas folks?