#2 – The Smallest Possible C# Program

The smallest possible C# program would consist of a static Main() function inside of a class. The namespace is actually optional, as is the args parameter.

using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("2,000 Things Was Here..");
        }
    }
}



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

6 Responses to #2 – The Smallest Possible C# Program

  1. Pingback: #6 – An Even Smaller C# Program « 2,000 Things You Should Know About C#

  2. alan says:

    You can shrink it trivially – you don’t need a namespace declaration 😉

  3. msuworld says:

    I know this ..yeah

  4. Parveen Arora says:

    class Program
    {
    static void Main()
    {
    }
    }
    I think this will work also.

    • Sean says:

      This will compile, but doesn’t actually do anything.

      • A simple program with an entry point that has no contents in the method body will result in an application that opens up a console window, finalizes, and closes. It’s hundreds if not thousands of times more “stuff” than the smallest possible C or assembly program (by number of actual instructions) on Windows. That sounds like more than nothing to me.

        If you talk about the total size of the application (memory, stack use, number of instructions), printing a string is also not the way to go. Calling a method requires an additional IL instruction and if it takes arguments then you have to deal with pushing those to the stack.

        I don’t see how this is the smallest C# program in either context.

Leave a comment