4
\$\begingroup\$

I found an old post on Jon Skeet's blog that pointed out a puzzle from a tweet by Vladimir Reshetnikov:

C# quiz: write a valid C# program containing a sequence of three tokens ? null : that remains valid after we remove the null.

Note that the wording "three tokens" is important: "? null :" is a single string literal token, and comments are not tokens.

Neither the tweet replies nor the blog comments contain an answer (nor do later tweets or blog posts). I googled and couldn't find any other discussion of the problem aside from those two sources. I wasted over an hour trying different things to no avail, although I suspect it has something to do with Nullable types and case statements or maybe statement labels.

This seems right up PCG's alley, so I'll award the check to the first submission that compiles in .Net 4.x (specify version) both with and without the null present.

\$\endgroup\$
  • \$\begingroup\$ There's a comment on the blog post linking to an example that works for me in ideone and mono, at least. ideone.com/QUhTNw \$\endgroup\$ – Geobits Jul 30 '15 at 20:25
  • \$\begingroup\$ I noticed that, but it doesn't work in .Net, so I don't think it's the intended solution. In any case I'll add a note to the question. \$\endgroup\$ – Sabre Jul 30 '15 at 20:29
  • 5
    \$\begingroup\$ Using @downvoter does no good. It pinged me, since I was the only previous user to comment, even though I didn't downvote this (contrary to what my avatar would lead you to believe). However, I think it's safe to say that if the downvoter cared to elaborate, they would have. \$\endgroup\$ – Geobits Jul 30 '15 at 21:31
  • \$\begingroup\$ Since it's possible that there might be more than one solution, I think it's a good idea to either never accept an answer or accept one after a week or so. \$\endgroup\$ – Jwosty Jul 30 '15 at 22:17