C# .NET Quizzes

Colin has a nice little quiz about enumeration on his blog. Basically he asks, how would you implement a class to enumerate through all the letters of the alphabet. Below is my "cute" response.

using System;
using System.Collections;
 
public class Alphabet : IEnumerable
{
  public IEnumerator GetEnumerator()
  {
    return "abcdefghijklmnopqrstuvwxyz".GetEnumerator();
  }
}

Now if you compile my answer and run it, it seems to answer the question correctly (for an academic quiz), but it's completely wrong for a real world developer. The right answer is "Well, which alphabet or alphabets must I support? Does it need to be localizable based on the current locale?".

Yes my friends, the answer is to gather more requirements. Make sure you really understand the problem domain. This is why software isn't as easy as "well I want it to do this so just do it." This quiz asks what seems to be a very straightforward question. If you as a developer gave me the solution I wrote above, I'd be pretty pissed as a client if I was ready to deploy this to Korea.

What others have said

Requesting Gravatar... Niels Hansen Jan 26, 2005 2:29 PM
# re: C# .NET Quizzes
Well the first question the client should have asked the developer before starting should have been:
"Are you qualified to write software in Korean?"

Now I see why this project was doomed from the very beginning! :)
Requesting Gravatar... Haacked Jan 26, 2005 2:33 PM
# re: C# .NET Quizzes
Schoolchildren in Korea will never learn their alphabet. All because of a doomed software project. How terrible.
Requesting Gravatar... Colin Jan 26, 2005 3:55 PM
# re: C# .NET Quizzes
If you were the client, and you asked me something like "Coller?, ??? ??? ??? ?? ??? ??? ???? ??? ??????", I'd probably change my approach. :)
Requesting Gravatar... Colin Jan 26, 2005 3:57 PM
# re: C# .NET Quizzes
Imagine that those ?s are Hangul.
Requesting Gravatar... Haacked Jan 26, 2005 4:57 PM
# re: C# .NET Quizzes
Ha ha, you'll have to use the Romanized version. ;) Anyoung Haseyo!
Requesting Gravatar... OmegaMan Apr 16, 2006 1:19 PM
# re: C# .NET Quizzes
It doesn't answer your real goal, but to enumerate an alphabet without the overhead of a class try this

char ch;
for (int index = 0; index < 26; index++)
{
char ch = Convert.ToChar((Convert.ToInt32('A') + index));
System.Console.Writeline(ch.ToString());
}

It harkens back to the old C days when one could simply add one to a character and get the next character in the sequence.
Requesting Gravatar... Asif Dec 22, 2007 2:22 AM
# re: C# .NET Quizzes
good

What do you have to say?

(will show your gravatar)
Please add 4 and 1 and type the answer here: