I was writing some code in C#, and I found myself writing:
return new MyClass(...
when I noticed that both the return
and the new
were both C# keywords. So I wondered what is the longest legal sequence of keywords in C#. All I could think of is:
internal static override void MyFunc(...
Where internal static override void
are all keywords. Can you think of a longer sequence of keywords?
Note: There's really no point to the question. I'm just hoping to pour more some fun on the fire :-)
That's 5.
For 6:
Edit for 7:
If we allow brackets and braces...
(edited the "lock", "new object()", "as" and "string" were contributed by others; see comments)
Can I cheat?
Using the fact that I can use a keyword or other reserved term as a variable name if I prepend it with an @ - comes in at 9 if you allow the duplication of StringBuilder.
Here is another case that can be as long as you wish:
With contextual keywords you can also have
One more variant with method definition (found by my colleague):
Makes 8 keywords in a row. Uses the fact that
await
is a contextual keyword, so it can be reused for method name.I guess it's infinite: