#6 – An Even Smaller C# Program
June 23, 2010 6 Comments
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() { } }
you could shorten the class name and get rid of whitespace for a even “shorter” program
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.
“Smallest possible C# program” actually means something specific … namely “class X{static void Main()}” where X can be replaced by any other letter.
@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
People get pedantic here, don’t they!
They certainly do. But my motto is: if it makes them feel intelligent or superior, have at it! ;o)