C# program containing `? null :` that is still valid without `null`

4

2

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.

Sabre

Posted 2015-07-30T20:08:59.327

Reputation: 157

Question was closed 2015-08-05T17:27:23.953

There's a comment on the blog post linking to an example that works for me in ideone and mono, at least. http://ideone.com/QUhTNw

– Geobits – 2015-07-30T20:25:41.577

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. – Sabre – 2015-07-30T20:29:06.497

5Using @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. – Geobits – 2015-07-30T21:31:17.593

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. – Jwosty – 2015-07-30T22:17:54.440

No answers