Hello World In C # without semicolon


Is it possible to write Hello World like in C without semicolon;?

In C:

  if(printf("Hello World!"))  //prints Hello World

In C#:

//do stuff

The trick is somehow constructing an expression from something that returns void. And luckily BeginInvoke does just that. Now we need to prevent the program from terminating before BeginInvoke wrote the text. Originally I just used a loop for that, but as SLaks showed we can use .AsyncWaitHandle.WaitOne() instead because it returns a bool.

Put this into the Main function:

if(((System.Action<string>)System.Console.WriteLine).BeginInvoke("Hello world",null,null).AsyncWaitHandle.WaitOne())