Member functions do not have to be static; but if they are not static, this requires creating an instance of the Program object to call the member method.
With static methods:
public class Program { public static void Main() { System.Console.WriteLine(Program.Foo()); } public static string Foo() { return "Foo"; } }
Without static methods (in other words, you need to instantiate a Program ):
public class Program { public static void Main() { System.Console.WriteLine(new Program().Foo()); } public string Foo()
Main should be static, because otherwise you would need to tell the compiler how to create an instance of the Program class, which may or may not be a trivial task.
Mark Rushakoff Nov 06 '09 at 6:00 2009-11-06 06:00
source share