tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

How many keywords I can fit into a single C# expression?

6 Feb 2019 1 mins C#

As I was playing few days ago with yield return await I got an idea to try fit as much “keywords” as possible into one “expression”. I mean as much blue words (in Visual Studio’s default colors) as possible together (not separated by semicolon, comma, colon, bracket, etc.).

Obviously yield return await gives us 3 together. One can also do yield return this, yield return base or yield return sizeof(...). But that’s still just 3. Can I do more? While I was waiting for my car on a yearly checkup, hence I was not mindlessly wasting time, I came up with 7.

class C
{
	async Task Test()
	{
		switch (this)
		{
			case null when await this is false:
				break;
		}
	}

	public System.Runtime.CompilerServices.TaskAwaiter<bool?> GetAwaiter() => default;
}

The case null when await this is false is the answer. At this point I ran out of time as I received a message from the garage that my car is ready. Maybe you can come up with even longer solution and I’m eager to see it.

Related post.

Profile Picture Jiří Činčura is an independent developer, .NET, C# and Firebird expert, focusing on data and business layers, language constructs, parallelism, databases and performance. He's Microsoft Most Valuable Professional and frequent speaker. You can read his articles, guides and tips and tricks at www.tabsoverspaces.com.