Okay - so the title's a bit misleading, but I thought it might peak interest :-) At Win-Dev this week, Frank Redmond asked the track chairs and some Microsoft folks to come up with a few short programming puzzles that he could use to raffle off some swag. As the chair for the CLR/C# track, I submitted a few. We didn't have room for all of the submissions, so I thought I'd post one that didn't make it up on a whiteboard here. It has got to be one of the ugliest pieces of code I've ever written.
What does the following program display? Explain your answer (an answer w/o an accurate explanation doesn't count). Compile with your eyes only.
using System;
using System.Collections;
using System.IO;
class Quiz {
static void Main() {
foreach( char c in CO("Hello, world!") ) {
Stream.Null.BeginWrite(
new byte[]{0x21}, 0, 1,
delegate(IAsyncResult r) {
Console.Write(r.AsyncState);
Stream.Null.EndWrite(r);
},
c
);
}
Console.ReadLine();
}
static IEnumerable CO(string s) {
foreach (char c in s.ToCharArray()) {
yield return c;
}
}
}
Posted
Oct 27 2004, 04:10 AM
by
mike-woodring