A Quick C# Teaser

Look at the following C# code, and work out why it compiles:

namespace X
{
  class Foo
  {
    void Bar()
    {

http://www.hackification.com

      System.Console.WriteLine();
    }
  }
}

(Hint: it’s not an error, but it is a warning.)

Idea originally from here.

Oh – and please, please, please – don’t even think about using this as an interview question.

3 Responses to “A Quick C# Teaser”

  1. Why don’t you want us to use it in a interview? It was my first thought.

  2. Is it because labels are bad! bad! bad! programming style?

  3. @Johan – why not as an interview question? Because it isn’t testing the candidate for the skills you want (ability to code useful systems), rather it tests to see whether they (a) know the largely useless corners of a language, and (b) are fluent in obfuscated coding. (And maybe [c] – has seen this trick question before).

    Another reason is that in general questions that the candidate either knows or doesn’t know the answer to can be handled in a pre-screening process (eg a test), if you want to do that sort of thing. Better questions allow you as an interviewer to guide the interviewee towards the answer – and the amount of “hand-holding” needed gives a good idea of the capability of the person.

Leave a Reply