Tuesday, September 21, 2010

Main() method in C#

  • The Main method is the entry point of your program, where the program control starts and ends.


class TestClass
{ static void Main(string[] args)
{ // Display the number of command line arguments:
System.Console.WriteLine(args.Length);
}
}
  • It is declared inside a class or struct. It must be static and it should not be public. (In the example above it receives the default access of private.)

  • It can either have a void or int return type.

  • The Main method can be declared with or without parameters.

  • Parameters can be read as zero-indexed command line arguments.

Source:msdn

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.