C# .NET Quizzes

0 comments suggest edit

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.

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.

Comments

avatar

9 responses

  1. Avatar for Niels Hansen
    Niels Hansen January 26th, 2005

    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! :)

  2. Avatar for Haacked
    Haacked January 26th, 2005

    Schoolchildren in Korea will never learn their alphabet. All because of a doomed software project. How terrible.

  3. Avatar for Colin
    Colin January 26th, 2005

    If you were the client, and you asked me something like "Coller?, ??? ??? ??? ?? ??? ??? ???? ??? ??????", I'd probably change my approach. :)

  4. Avatar for Colin
    Colin January 26th, 2005

    Imagine that those ?s are Hangul.

  5. Avatar for Haacked
    Haacked January 26th, 2005

    Ha ha, you'll have to use the Romanized version. ;) Anyoung Haseyo!

  6. Avatar for OmegaMan
    OmegaMan April 16th, 2006

    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.

  7. Avatar for Asif
    Asif December 21st, 2007

    good

  8. Avatar for Naveen
    Naveen September 24th, 2010

    what is the actully mean of .net

  9. Avatar for nithiya
    nithiya November 11th, 2010

    we are want more example programms for quiz test