"Hello World" without a Semicolon ";"

S

Stefan Ram

I can write a Java program that can print "hello, world",
while the source code does not contain a semicolon:

class Main
{ public static void main( java.lang.String[] args )
{ if( java.lang.System.out.printf( "hello, world%n" )== null ){} }}

Can a program be written in C# (using only the standard
libraries), that prints "hello, world" and whose source
code does not contain a semicolon »;«?
 
P

Peter Duniho

Stefan said:
I can write a Java program that can print "hello, world",
while the source code does not contain a semicolon:

class Main
{ public static void main( java.lang.String[] args )
{ if( java.lang.System.out.printf( "hello, world%n" )== null ){} }}

Can a program be written in C# (using only the standard
libraries), that prints "hello, world" and whose source
code does not contain a semicolon »;«?

Sure. It's a little wordier because .NET's equivalent to
System.out.printf() returns 'void' and so has to be wrapped in something
that doesn't. But it works:

class Program
{
static void Main(string[] args)
{
if (((System.Action)(() => System.Console.WriteLine("hello,
world"))).DynamicInvoke() == null) { }
}
}

Since the exercise is clearly arbitrary and not related to getting any
real program working, I expect half whatever the reward is when you turn
this solution in. ;)

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top