#6 – An Even Smaller C# Program

In The Smallest Possible C# Program, I mentioned a couple things as optional.  For the record, here’s the absolute smallest C#.NET program that you can write.  (Assuming that you don’t need it to actually do anything).

class Program
{
    static void Main()
    {
    }
}
Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

6 Responses to #6 – An Even Smaller C# Program

  1. Mark Kane says:

    you could shorten the class name and get rid of whitespace for a even “shorter” program

    • Sean says:

      That’s technically true, that you could remove whitespace and shorten the class name. But choosing meaningful names and properly formatting your code is important for purposes of maintainability. Also, the resulting program would not be any shorter, in terms of the number of elements and the resulting IL. The point of this post was to look at the core elements of a C# program, from a semantic point of view, rather to use the smallest number of characters for some reason.

      • jibalt says:

        “Smallest possible C# program” actually means something specific … namely “class X{static void Main()}” where X can be replaced by any other letter.

      • StuMonk says:

        @jibalt

        Do enlighten us as to where you divined the specific meaning of “smallest possible program.” Does it mean number of lines of emitted IL? Perhaps the count of the total native code bytes? Or maybe source code file size?

        Also, as long as we’re nitpicking unnecessarily, your sample code is wrong and your note that follows is incomplete (double whammy).

        – Your “main” function is missing the opening/closing braces after the parentheses
        – ‘X’ can be replaced by an underscore as well

        Sheesh

  2. Bill says:

    People get pedantic here, don’t they!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: