# Shortest Hello World program with no semi colons

I recently saw some questions on SO that asked if you could make a Hello World program without using any semi colons using C#. The challenge is to do this again, but in the shortest amount of code possible!

• I assume this is meant to be a language-specific challenge? Otherwise there are plenty of languages where this task would be trivial. (For example, 'Hello World' is a valid GolfScript program that prints Hello World. Although HQ9+ will easily beat it.) – Ilmari Karonen Apr 17 '12 at 14:51
• @llmari Sorry, yes, I have updated question. I would have tagged it C# but it doesn't exist and I don't have the rep to create it, thanks. – Bali C Apr 17 '12 at 15:41

# C#, 76

class X{static void Main(){if(System.Console.Write("Hello, World!")is X){}}}


I tried this in my VS2012 and it works just fine, even though it is quite a surprise that you can apply the is operator to void...

# C# 85 chars

class H{static void Main(){if(System.Console.Out.WriteAsync("Hello, world!")is H){}}}

• Which .NET version is this? .NET 4 doesn't seem to contain a definition for TextWriter.WriteAsync(). – primo Apr 26 '12 at 6:45
• @primo .NET 4.5 does. – Bob Apr 26 '12 at 10:58

## C# (114)

class M{static void Main(){if(typeof(System.Console).GetMethods()[78].Invoke(null,new[]{"Hello, world!"})is M){}}}


Note that the proper index for Write(string)/WriteLine(string) may be different on your system. However, since there are only 106 methods total, I'm almost certain either Write(string) or WriteLine(string) will be a two-digit index number on every system, so the character count should be generally valid.

Demo: http://ideone.com/5npky (Write method is apparently index 23 here)

• This solution is brilliant. +1 – primo Apr 22 '12 at 10:40
• I also thought is was ironic that after putting it together, it came out exactly 1 character shorter than yours :) – mellamokb Apr 23 '12 at 17:25
• Can save three characters by changing null to 0. Get a nice character count of 111 :) – Timwi Aug 3 '13 at 9:02

# 115 Bytes

class H{static void Main(){if(((System.Action)(()=>System.Console.Write("Hello, world!"))).DynamicInvoke()is H){}}}


It's likely possible to produce something a bit shorter, but I'm pretty sure that you're going to need make some sort of asynchronous call.

# C# 9695 94 chars

A bit of a cheat, but works if you have IronRuby installed:

class P{static void Main(){if(IronRuby.Ruby.CreateEngine().Execute("puts'Hello World'")>1){}}}

• You can save 1 char by replacing == with a one-character comparison operator. – Peter Taylor Apr 19 '12 at 9:42
• @PeterTaylor I've updated the code. Thanks for this great suggestion! – Cristian Lupascu Apr 19 '12 at 9:47
• I also removed the space between puts and the string. puts'Hello World' is valid ruby code – Cristian Lupascu Apr 19 '12 at 9:49