#2 – The Smallest Possible C# Program
June 19, 2010 6 Comments
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.."); } } }
Pingback: #6 – An Even Smaller C# Program « 2,000 Things You Should Know About C#
You can shrink it trivially – you don’t need a namespace declaration 😉
I know this ..yeah
class Program
{
static void Main()
{
}
}
I think this will work also.
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.