Skip to main content
5 of 6
added 3 characters in body
Timwi
  • 13k
  • 3
  • 46
  • 66

C# (175 chars)

It was quite a challenge to do this in C# because the restrictions preclude any use of quite a lot of the common keywords. It is possible in C# to use \uxxxx Unicode escape sequences in identifiers, but unfortunately not in keywords.

I suspect that this solution only works when compiled against .NET 4.0. See explanation for why.

using System;struct a{static int Main(){object[]c={"\u0048e\x6c\x6co "+(C\u0068ar)(86+1)+"or\x6c\x64"};typeof(Conso\u006ce).GetMet\u0068o\u0064s()[101].Invoke(c,c);return 0;}} 

Explanation:

// I won’t be able to get anywhere without using “System”. // Even if I write it as “Syst\u0065m”, it still violates rule 2. // Therefore, that is the rule we’ll violate. using System; // Thus, we can’t use: H L W D 2 7 // We can’t write “class”, so the Main type must be a struct. struct a { // We can’t write “void”, so Main needs to return an int. static int Main() { // We can’t write “new”, but we can instantiate an array // using the initialisation syntax. object[] c = { "\u0048e\x6c\x6co " + (C\u0068ar) (86 + 1) + "or\x6c\x64" }; // We can use the character escape sequence to write “Console”, but not // “Write” because W is \u0057, which contains a 7. Therefore, we have to // use Reflection to get it. This relies on the fact that Console.Write(string) // is method #101 in my copy of the framework. // Also, the first argument can be anything (needn’t be null) for a static method. typeof(Conso\u006ce).GetMet\u0068o\u0064s()[101].Invoke(c, c); // Since Main returns int, we have to return something. return 0; } } 
Timwi
  • 13k
  • 3
  • 46
  • 66