只使用C#关键字,您可以制作的最长法律声明块是什么?
我在C#中编写了一些代码,我发现自己在编写:
return new MyClass(...
当我注意到return
和new
都是C#关键字时。 所以我想知道C#中最长的关键字合法序列是什么。 我能想到的只有:
internal static override void MyFunc(...
internal static override void
都是关键字。 你能想到更长的关键词序列吗?
注意:这个问题确实没有意义。 我只是希望在火上倒一些乐趣:-)
6:
new protected internal unsafe virtual decimal Foo() {...}
编辑7:
new protected internal unsafe virtual extern decimal Foo();
如果我们允许括号和括号……
( 编辑 “锁定”,“新对象()”,“as”和“字符串”由其他人提供;见评论)
decimal Bar() { lock (new object() as string) { if (true) { checked { unsafe { try { do { return default(decimal); unchecked {break;} continue; } while (false); } catch { throw; } finally { } } } } } }
我想这是无限的:
return null as string as string as string as string as string....
这是另一个案例,只要你愿意:
do do do do do do do do do do do do do do do // ... while(x) while(x) while(x) while(x) while(x) // ...
使用上下文关键字,您也可以拥有
await await await await await await await // ...
internal protected static volatile string foo = "bar";
那是5。
另一种方法定义的变体(由我的同事发现):
protected internal override sealed unsafe async void await() { ... }
连续制作8个关键字。 使用await
是一个上下文关键字的事实,因此它可以重用于方法名称。
我可以作弊吗?
internal protected static volatile StringBuilder @string = new StringBuilder(int.Parse("12"));
使用关键字或其他保留术语作为变量名称的事实,如果我在前面加上@ – 如果允许重复StringBuilder,则在9处。