September 8, 2024

The first C# Program

Here it is:
Console.WriteLine ( "Kilroy was here." );
One line of code! This builds and runs just fine with C# 12. This would not build with older versions of C# (notably Mono). Having code outside of a class is what they call a "Top level statement" and only became legal as of C# 10.

The truth is that the compiler wraps this in the usual ceremony (boilerplate code) for you, so you are just in essence "tricking yourself".
But it makes a dandy one line first C# program to use as a teaser.

The slogan "Kilroy was here" dates back to WW-II graffiti.
Feedback? Questions? Drop me a line!

Tom's Computer Info / tom@mmto.org